The syntax

The real power of jQuery lies in its custom made syntax, which will help in selecting HTML elements and perform some action. Its syntax is quite straightforward and easy to remember, plus it's very neatly written. Here is a sample of jQuery syntax:

$(selector).action ()

The dollar sign ($) defines whether you will use jQuery, whereas the selector query is to find the HTML element and action defines what kind of action will be performed on selected elements.

Here are some examples that will explain how jQuery works using its syntax:

  • $(this).hide(): This hides the current element
  • $("p").hide(): The hides all <p> elements
  • $(".test").hide(): This hides all elements with class="test"
  • $("#test").hide(): This hides the element with id="test"

These ...

Get Mastering JavaScript Promises now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.