Tuesday, May 27, 2014

Example of jQuery Syntax

1)
Basic syntax is: $(selector).action()
  • A $ sign to define/access jQuery
  • A (selector) to "query (or find)" HTML elements
  • A jQuery action() to be performed on the element(s)
2) Examples:
  • $(this).hide() - hides the current element.
  • $("p").hide() - hides all <p> elements.
  • $(".test").hide() - hides all elements with class="test".
  • $("#test").hide() - hides the element with id="test".
2) use of $(document).ready(function(){});

This is to prevent any jQuery code from running before the document is finished loading (is ready).
    

No comments:

Post a Comment