際際滷

際際滷Share a Scribd company logo
jQuery fundamentals
   Introduction
                         Selector
Agenda                   Interacting with the DOM
What we will learn!
                         Handling Events
                         Working with Ajax Features
                         Tools and documentation
How can I become an English guy
   Learn the language

   Use the dictionary

   Speak a lot

   Drink a lot of (Yorkshire) tea with milk and beer off course
鴛稼岳姻看糸顎界岳庄看稼
     , Nino Crudele




     Stay relax
Why use jQuery
   First of all what you need to know:
     Javascript
     Html
     Css

   Why jQuery is so famous?
       JavaScript Library (single file)
       Cross-browser support
       Selector
       Handle events
       Animate
       Post and Get (Ajax calls)
       A lot of plugins available
What is DOM?
   http://www.w3.org/TR/DOM-Level-2-Core/introduction.html
   The Document Object Model (DOM) is an application programming interface
    (API) for valid HTML and well-formed XML documents. It defines the logical
    structure of documents and the way a document is accessed and manipulated.
    In the DOM specification, the term "document" is used in the broad sense -
    increasingly, XML is being used as a way of representing many different kinds of
    information that may be stored in diverse systems, and much of this would
    traditionally be seen as data rather than as documents. Nevertheless, XML
    presents this data as documents, and the DOM may be used to manage this
    data.
   With the Document Object Model, programmers can build documents, navigate
    their structure, and add, modify, or delete elements and content. Anything found
    in an HTML or XML document can be accessed, changed, deleted, or added
    using the Document Object Model, with a few exceptions - in particular, the
    DOM interfaces for the XML internal and external subsets have not yet been
    specified.
What DOM looks like
Learn the language
   From Shawn Wildermuth - JavaScript for the C# Guy:
       http://wildermuth.com/2012/5/6/JavaScript_for_the_C_Guy_The_Global_Object
       http://wildermuth.com/2012/3/16/JavaScript_for_the_C_Guy_Scopes
       http://wildermuth.com/2012/3/10/JavaScript_for_the_C_Guy_Function_Overloads
       http://wildermuth.com/2012/5/28/JavaScript_for_the_C_Guy_The_confusion_about_this
Using jQuery Ready Function
   $(document).ready()
     Each HTML document loaded into a browser window becomes a document object


<script type="text/javascript" language="javascript">
            $(document).read(function() {
                        // do it
            });
</script>


   What means $?
     The $ is a identifier. jQuery use it as the primary base object (or function). Ex:
<script type="text/javascript" language="javascript">
            var 畩 = function (object) {
                        object.Company = "Content and Code";
                        return object;
            };

            alert(畩(document).Company);

</script>
Use the dictionary
   http://api.jquery.com -> it will be your best friend

   If you want intellisense works with jquery, look that:
    http://appendto.com/community/jquery-vsdoc

   SP ///   <reference path="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7-vsdoc.js" />
Demo - Referencing a jQuery Script
Speak a lot

              Selector
Selecting Nodes by: id, class name,
attribute name
   Different ways to select a node:
     By id:
        $(#myDiv)
        $(div[id])
     By class:
        $(.myClass)
     By attribute:
        $(div[id])
        $(input[name~=man])
Demo Selector
  $(#myDiv)
  $(div[id])
  $(.myClass)
The Other Selectors
   ~= contains a word
   |= contains a prefix
   *= contains a string in the word
   = equals
   != not equal
   ^= start with
   :button is a button
   :checkbox is a checkbox
   :checked is a checked checkbox
Demo The Other Selector
Speak a lot
              Interacting
              with the DOM
Iterating Through Nodes
.each(function (index, Element)) is used to iterate through jQuery objects:

$('div')
       .each(function(index) {
              alert(index +   + $(this).text());
       });

-----------------

   $('.row').last().remove();

-----------------

var newBox = $('<div class="tile"
id="bb"></div>').addClass(colorOfMyNewBox);
var lastrow = $('.row').last();
newBox.appendTo(lastrow);
Demo Modify Properties and Attributes
   Object attributes can be accessed using attr():

var val = $('#logo').attr('title');

$('#logo').attr('title, new logo title);

$('#addBox').attr({
       title: '',
       css: {
              'border': '2px solid black;
       }
});
Demo Adding and Removing nodes
$('#addRow').click(function () {
    $('<div class="row"></div>').appendTo('.list');
});


$('#removeLastBox').click(function () {
    $('.tile').last().remove();
});
Speak a lot   Handling
              Events
Demo Handling Events
$(function() {
       $(".tile").mousedown(function() {
               $(this).addClass("selectedTile");
       });
       $(".tile").mouseup(function() {
               $(this).removeClass("selectedTile");
       });
});

$('#removeLastBox').bind('click', function() {});

$('#removeLastBox').unbind('click');
Speak a lot   Ajax
              Features
Load function
$(document).ready(function () {
       $('#mockData').click(function () {
              $('#displayMockData').load('mockData.hmtl');
       });
});



$('#displayMockData').load('mockData.hmtl #faq3');



$('#displayMockData').load(GetCustomers.aspx', {PageSize:25});
.get() and .post() functions
$.get('/Examples/GetBoxes',
           function (data) {
                      var list = $('<div class="list"></div>');
                      var newRow = $('<div class="row"></div>').appendTo(list);
                      var newBoxes = '';
                      $.each(data, function (index, item) {
                                 newBoxes += '<div class="' + item.CssClass + '" id="' + item.Id +
'" title="' + item.Tlt + '"></div>';
                      });
                      $(newRow).append(newBoxes);
                      $(list).appendTo('#displayMockDataFromServer');
           });



$.post('/Product/UpdateProduct', { Id: dto.id, Name: dto.name, Color: dto.color, ListPrice:
dto.price, ProductModel: dto.model, Quantity: dto.qty },
           function () {
                      dto.edit(false);
           });
Tools
   Vsdoc
   /// <reference path="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7-
    vsdoc.js" />
   http://jsfiddle.net/
   Fiddler
   Chrome developer tools
Drink a lot of (Yorkshire) tea with milk and
beer off course

Whats next to make my UI more
atractive (I mean Rich)
                                    http://knockoutjs.com/

                                    http://backbonejs.org/
                                     (https://touch.www.linkedin.com/)

                                    http://linqjs.codeplex.com/

                                    http://www.typescriptlang.org

                                    http://signalr.net/

More Related Content

What's hot (20)

jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
Bedis ElAch竪che
The Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contribThe Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contrib
Tzu-ping Chung
FuncUnit
FuncUnitFuncUnit
FuncUnit
Brian Moschel
jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)
Addy Osmani
Handlebars.js
Handlebars.jsHandlebars.js
Handlebars.js
Ivano Malavolta
Jquery introduction
Jquery introductionJquery introduction
Jquery introduction
musrath mohammad
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
prince Loffar
User Interface Development with jQuery
User Interface Development with jQueryUser Interface Development with jQuery
User Interface Development with jQuery
colinbdclark
Js ppt
Js pptJs ppt
Js ppt
Rakhi Thota
Nothing Hard Baked: Designing the Inclusive Web
Nothing Hard Baked: Designing the Inclusive WebNothing Hard Baked: Designing the Inclusive Web
Nothing Hard Baked: Designing the Inclusive Web
colinbdclark
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
WebStackAcademy
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
Gill Cleeren
The jQuery Library
The  jQuery LibraryThe  jQuery Library
The jQuery Library
LearnNowOnline
Javascript by geetanjali
Javascript by geetanjaliJavascript by geetanjali
Javascript by geetanjali
Geetanjali Bhosale
Intro to jQuery
Intro to jQueryIntro to jQuery
Intro to jQuery
Alan Hecht
Lecture 6: Client Side Programming 2
Lecture 6: Client Side Programming 2Lecture 6: Client Side Programming 2
Lecture 6: Client Side Programming 2
Artificial Intelligence Institute at UofSC
Associations & JavaScript
Associations & JavaScriptAssociations & JavaScript
Associations & JavaScript
Joost Elfering
Javascript tutorial
Javascript tutorialJavascript tutorial
Javascript tutorial
Abhishek Kesharwani
Complete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScriptComplete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScript
EPAM Systems
Stack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersStack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for Developers
Jonathan Sharp
The Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contribThe Django Book, Chapter 16: django.contrib
The Django Book, Chapter 16: django.contrib
Tzu-ping Chung
jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)jQuery Performance Tips and Tricks (2011)
jQuery Performance Tips and Tricks (2011)
Addy Osmani
Learn javascript easy steps
Learn javascript easy stepsLearn javascript easy steps
Learn javascript easy steps
prince Loffar
User Interface Development with jQuery
User Interface Development with jQueryUser Interface Development with jQuery
User Interface Development with jQuery
colinbdclark
Nothing Hard Baked: Designing the Inclusive Web
Nothing Hard Baked: Designing the Inclusive WebNothing Hard Baked: Designing the Inclusive Web
Nothing Hard Baked: Designing the Inclusive Web
colinbdclark
JavaScript - Chapter 3 - Introduction
 JavaScript - Chapter 3 - Introduction JavaScript - Chapter 3 - Introduction
JavaScript - Chapter 3 - Introduction
WebStackAcademy
Getting started with jQuery
Getting started with jQueryGetting started with jQuery
Getting started with jQuery
Gill Cleeren
Intro to jQuery
Intro to jQueryIntro to jQuery
Intro to jQuery
Alan Hecht
Associations & JavaScript
Associations & JavaScriptAssociations & JavaScript
Associations & JavaScript
Joost Elfering
Complete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScriptComplete Notes on Angular 2 and TypeScript
Complete Notes on Angular 2 and TypeScript
EPAM Systems
Stack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for DevelopersStack Overflow Austin - jQuery for Developers
Stack Overflow Austin - jQuery for Developers
Jonathan Sharp

Similar to Jquery fundamentals (20)

jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
Doris Chen
SPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQuerySPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQuery
Mark Rackley
SPTechCon Boston 2015 - Utilizing jQuery in SharePoint
SPTechCon Boston 2015 - Utilizing jQuery in SharePointSPTechCon Boston 2015 - Utilizing jQuery in SharePoint
SPTechCon Boston 2015 - Utilizing jQuery in SharePoint
Mark Rackley
JavaScript!
JavaScript!JavaScript!
JavaScript!
RTigger
Jquery
JqueryJquery
Jquery
Zoya Shaikh
bcgr3-jquery
bcgr3-jquerybcgr3-jquery
bcgr3-jquery
tutorialsruby
bcgr3-jquery
bcgr3-jquerybcgr3-jquery
bcgr3-jquery
tutorialsruby
Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript Basics
EPAM Systems
jQuery
jQueryjQuery
jQuery
Vishwa Mohan
The Inclusive Web: hands-on with HTML5 and jQuery
The Inclusive Web: hands-on with HTML5 and jQueryThe Inclusive Web: hands-on with HTML5 and jQuery
The Inclusive Web: hands-on with HTML5 and jQuery
colinbdclark
Jquery Basics
Jquery BasicsJquery Basics
Jquery Basics
Umeshwaran V
jQuery Learning
jQuery LearningjQuery Learning
jQuery Learning
Uzair Ali
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
David Giard
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationLotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Sean Burgess
SPTechCon - Share point and jquery essentials
SPTechCon - Share point and jquery essentialsSPTechCon - Share point and jquery essentials
SPTechCon - Share point and jquery essentials
Mark Rackley
SEF2013 - A jQuery Primer for SharePoint
SEF2013 - A jQuery Primer for SharePointSEF2013 - A jQuery Primer for SharePoint
SEF2013 - A jQuery Primer for SharePoint
Marc D Anderson
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
Siva Arunachalam
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
toddbr
J Query Public
J Query PublicJ Query Public
J Query Public
pradeepsilamkoti
jQuery basics
jQuery basicsjQuery basics
jQuery basics
Stijn Van Minnebruggen
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
Doris Chen
SPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQuerySPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQuery
Mark Rackley
SPTechCon Boston 2015 - Utilizing jQuery in SharePoint
SPTechCon Boston 2015 - Utilizing jQuery in SharePointSPTechCon Boston 2015 - Utilizing jQuery in SharePoint
SPTechCon Boston 2015 - Utilizing jQuery in SharePoint
Mark Rackley
JavaScript!
JavaScript!JavaScript!
JavaScript!
RTigger
Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript Basics
EPAM Systems
The Inclusive Web: hands-on with HTML5 and jQuery
The Inclusive Web: hands-on with HTML5 and jQueryThe Inclusive Web: hands-on with HTML5 and jQuery
The Inclusive Web: hands-on with HTML5 and jQuery
colinbdclark
jQuery Learning
jQuery LearningjQuery Learning
jQuery Learning
Uzair Ali
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
David Giard
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationLotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Sean Burgess
SPTechCon - Share point and jquery essentials
SPTechCon - Share point and jquery essentialsSPTechCon - Share point and jquery essentials
SPTechCon - Share point and jquery essentials
Mark Rackley
SEF2013 - A jQuery Primer for SharePoint
SEF2013 - A jQuery Primer for SharePointSEF2013 - A jQuery Primer for SharePoint
SEF2013 - A jQuery Primer for SharePoint
Marc D Anderson
Javascript first-class citizenery
Javascript first-class citizeneryJavascript first-class citizenery
Javascript first-class citizenery
toddbr

Jquery fundamentals

  • 2. Introduction Selector Agenda Interacting with the DOM What we will learn! Handling Events Working with Ajax Features Tools and documentation
  • 3. How can I become an English guy Learn the language Use the dictionary Speak a lot Drink a lot of (Yorkshire) tea with milk and beer off course
  • 4. 鴛稼岳姻看糸顎界岳庄看稼 , Nino Crudele Stay relax
  • 5. Why use jQuery First of all what you need to know: Javascript Html Css Why jQuery is so famous? JavaScript Library (single file) Cross-browser support Selector Handle events Animate Post and Get (Ajax calls) A lot of plugins available
  • 6. What is DOM? http://www.w3.org/TR/DOM-Level-2-Core/introduction.html The Document Object Model (DOM) is an application programming interface (API) for valid HTML and well-formed XML documents. It defines the logical structure of documents and the way a document is accessed and manipulated. In the DOM specification, the term "document" is used in the broad sense - increasingly, XML is being used as a way of representing many different kinds of information that may be stored in diverse systems, and much of this would traditionally be seen as data rather than as documents. Nevertheless, XML presents this data as documents, and the DOM may be used to manage this data. With the Document Object Model, programmers can build documents, navigate their structure, and add, modify, or delete elements and content. Anything found in an HTML or XML document can be accessed, changed, deleted, or added using the Document Object Model, with a few exceptions - in particular, the DOM interfaces for the XML internal and external subsets have not yet been specified.
  • 8. Learn the language From Shawn Wildermuth - JavaScript for the C# Guy: http://wildermuth.com/2012/5/6/JavaScript_for_the_C_Guy_The_Global_Object http://wildermuth.com/2012/3/16/JavaScript_for_the_C_Guy_Scopes http://wildermuth.com/2012/3/10/JavaScript_for_the_C_Guy_Function_Overloads http://wildermuth.com/2012/5/28/JavaScript_for_the_C_Guy_The_confusion_about_this
  • 9. Using jQuery Ready Function $(document).ready() Each HTML document loaded into a browser window becomes a document object <script type="text/javascript" language="javascript"> $(document).read(function() { // do it }); </script> What means $? The $ is a identifier. jQuery use it as the primary base object (or function). Ex: <script type="text/javascript" language="javascript"> var 畩 = function (object) { object.Company = "Content and Code"; return object; }; alert(畩(document).Company); </script>
  • 10. Use the dictionary http://api.jquery.com -> it will be your best friend If you want intellisense works with jquery, look that: http://appendto.com/community/jquery-vsdoc SP /// <reference path="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7-vsdoc.js" />
  • 11. Demo - Referencing a jQuery Script
  • 12. Speak a lot Selector
  • 13. Selecting Nodes by: id, class name, attribute name Different ways to select a node: By id: $(#myDiv) $(div[id]) By class: $(.myClass) By attribute: $(div[id]) $(input[name~=man])
  • 14. Demo Selector $(#myDiv) $(div[id]) $(.myClass)
  • 15. The Other Selectors ~= contains a word |= contains a prefix *= contains a string in the word = equals != not equal ^= start with :button is a button :checkbox is a checkbox :checked is a checked checkbox
  • 16. Demo The Other Selector
  • 17. Speak a lot Interacting with the DOM
  • 18. Iterating Through Nodes .each(function (index, Element)) is used to iterate through jQuery objects: $('div') .each(function(index) { alert(index + + $(this).text()); }); ----------------- $('.row').last().remove(); ----------------- var newBox = $('<div class="tile" id="bb"></div>').addClass(colorOfMyNewBox); var lastrow = $('.row').last(); newBox.appendTo(lastrow);
  • 19. Demo Modify Properties and Attributes Object attributes can be accessed using attr(): var val = $('#logo').attr('title'); $('#logo').attr('title, new logo title); $('#addBox').attr({ title: '', css: { 'border': '2px solid black; } });
  • 20. Demo Adding and Removing nodes $('#addRow').click(function () { $('<div class="row"></div>').appendTo('.list'); }); $('#removeLastBox').click(function () { $('.tile').last().remove(); });
  • 21. Speak a lot Handling Events
  • 22. Demo Handling Events $(function() { $(".tile").mousedown(function() { $(this).addClass("selectedTile"); }); $(".tile").mouseup(function() { $(this).removeClass("selectedTile"); }); }); $('#removeLastBox').bind('click', function() {}); $('#removeLastBox').unbind('click');
  • 23. Speak a lot Ajax Features
  • 24. Load function $(document).ready(function () { $('#mockData').click(function () { $('#displayMockData').load('mockData.hmtl'); }); }); $('#displayMockData').load('mockData.hmtl #faq3'); $('#displayMockData').load(GetCustomers.aspx', {PageSize:25});
  • 25. .get() and .post() functions $.get('/Examples/GetBoxes', function (data) { var list = $('<div class="list"></div>'); var newRow = $('<div class="row"></div>').appendTo(list); var newBoxes = ''; $.each(data, function (index, item) { newBoxes += '<div class="' + item.CssClass + '" id="' + item.Id + '" title="' + item.Tlt + '"></div>'; }); $(newRow).append(newBoxes); $(list).appendTo('#displayMockDataFromServer'); }); $.post('/Product/UpdateProduct', { Id: dto.id, Name: dto.name, Color: dto.color, ListPrice: dto.price, ProductModel: dto.model, Quantity: dto.qty }, function () { dto.edit(false); });
  • 26. Tools Vsdoc /// <reference path="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7- vsdoc.js" /> http://jsfiddle.net/ Fiddler Chrome developer tools
  • 27. Drink a lot of (Yorkshire) tea with milk and beer off course Whats next to make my UI more atractive (I mean Rich) http://knockoutjs.com/ http://backbonejs.org/ (https://touch.www.linkedin.com/) http://linqjs.codeplex.com/ http://www.typescriptlang.org http://signalr.net/