1 / 87

CHAPTER 7 JQUERY

CHAPTER 7 JQUERY. WHAT IS JQUERY?. jQuery is a script. It is written in JavaScript. Once included in your page, it is used to: Select elements Do things with the elements you selected. 1. 1. Select elements using CSS-style selectors. jQuery(‘li.hot’);. jQuery( ‘li.hot’ ) ;. FUNCTION.

dutch
Download Presentation

CHAPTER 7 JQUERY

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CHAPTER 7JQUERY

  2. WHAT IS JQUERY?

  3. jQuery is a script.It is written in JavaScript.

  4. Once included in your page, it is used to:Select elementsDo things with the elements you selected

  5. 1

  6. 1 Select elements using CSS-style selectors

  7. jQuery(‘li.hot’);

  8. jQuery(‘li.hot’); FUNCTION

  9. jQuery(‘li.hot’); CSS-STYLE SELECTOR

  10. $(‘li.hot’); SHORTHAND FOR JQUERY FUNCTION

  11. When you select an element or set of elements, it creates a jQuery object.

  12. That object contains references to the elements.

  13. Like any object, the jQuery object has properties and methods. They allow you to work with those elements.

  14. A jQuery object with selected elements can be called a:jQuery selectionormatched set

  15. 2

  16. 1 2 Select elements using CSS-style selectors Do something using methods of the jQuery object

  17. $(‘li.hot’).hide(); HIDE ALL MATCHING LIST ITEMS METHOD OF THE JQUERY OBJECT

  18. With jQuery, you can:Select or find elementsUpdate their content / size / visibilitySimplify event handling

  19. STORING SELECTIONS IN VARIABLES

  20. When a variable holds a jQuery object, its name often begins with a $ symbol.

  21. var $titles = $(‘.title’);

  22. var $titles = $(‘.title’); VARIABLE NAME

  23. var $titles = $(‘.title’); CSS-STYLE SELECTOR

  24. CSS-STYLE SELECTORSThis variable holds a jQuery object containing the element whose id attribute has a value of author:var $author = $(‘#author’);

  25. CSS-STYLE SELECTORSThis variable holds a jQuery object containing the first item from the unordered list whose id attribute has a value of list:var $first = $(‘ul#list:first-child’);

  26. GETTING & SETTING INFORMATION

  27. GETTING HTML CONTENTThe .html() method gets the content of the selection (including markup).It only retrieves content from the first element in the matched set.

  28. GETTING HTML CONTENTThis example retrieves the content of the first list item.$(‘li’).html();

  29. GETTING TEXT CONTENTThe .text() method gets the text content only of the selection (excluding markup).

  30. GETTING TEXT CONTENTThis example retrieves the text content of the first list item.$(‘li’).text();

  31. SETTING CONTENTNew content is added inside the parentheses after the method name.It updates all of the elements in the matched set (not just the first). This is known as implicit iteration.

  32. SETTING HTML CONTENTThis example will replace the content of each list item with the word Updated in <b> tags.$(‘li’).html(‘<b>Updated</b>’);

  33. SETTING TEXT CONTENTThis example will replace the text content of each list item with the word Updated.$(‘li’).text(‘Updated’);

  34. CHAININGIt is possible to call multiple methods on the same selection.$(‘li’).hide().fadeIn(500);

  35. CHAININGIt is possible to call multiple methods on the same selection.$(‘li’).hide().fadeIn(500); FIRST METHOD

  36. CHAININGIt is possible to call multiple methods on the same selection.$(‘li’).hide().fadeIn(500); SECOND METHOD

  37. CHECKING A PAGE IS READY TO WORK WITH

  38. jQuery’s .ready() method checks that the page is ready for your code to work with.

  39. $(document).ready(function() { // code goes here});

  40. $(document).ready(function() { // code goes here}); JQUERY OBJECT Creates a jQuery object containing the entire page

  41. $(document).ready(function() { // code goes here}); JQUERY METHOD Checks to see if the page has loaded before…

  42. $(document).ready(function() { // code goes here}); CODE …running the code inside the parentheses

  43. This is a shortcut for writing the .ready() method.

  44. $(document).ready(function() { // code goes here});

  45. $(function() { // code goes here});

  46. MORE ABOUT UPDATING ELEMENTS

  47. UPDATE ELEMENTS .html().replaceWith() .text() .remove() $(‘li#one’).remove();

  48. <li>item</li> .before() INSERT ELEMENTS .after() .prepend() .append()

  49. GET & SET ATTRIBUTES .attr().addClass() .removeAttr() .removeClass() $(‘a#top’).addClass(‘button’);

More Related