jQuery Syntax – Starting up with jQuery – basic syntax

jQuery Syntax

As such with jQuery HTML elements are selected and certain actions are performed on these elements. Syntax of jQuery is made accordingly:

$(selector).action()

So this is the basic syntax of jQuery where

  • $ = define or access jquery
  • (selecter) = is to find or refer HTML elements
  • Action() = jQuery action to perform on those elements

For example: $(“.resultset”).hide() Here $sign accesses jquery, which performs action to hide resultset class.

A basic example of jQuery

LIVE DEMO

So in the above example, if you click on “Click here to hide resultset class below:” text in browser it will hide yellow line with text . The “Click here to hide resultset class below:” is contained in <p> of and Yellow line in div class resultset. So what actually this jquery code does:

–      <script src=”http://code.jquery.com/jquery-1.10.1.min.js”></script> lines is used to call reference for jQuery library.

–       $(document).ready(function() of jquery is explained here, that ensures if  document is loaded then execute java script

–       Next lines $(“p”).click(function () specifies if paragraph is clicked anywhere then it will hide running this code               $(“.resultset”).hide();