jQuery syntax

We will now have a look at the jQuery syntax.  The following syntax is an example of a jQuery and JavaScript code that changes the background of the body:

jQuery$('body').css('background', '#fff'); Javascriptfunction changeBackgroundColor(color) {
   document.body.style.background = color;
}
onload="changeBackgroundColor('white');"

You can see the big difference between them. 

The basic syntax of jQuery is very simple:

$(selector).action();
  1. The $ sign starts any jQuery action
  2. The (selector) is used to query (or find) HTML elements, by ID or class like in CSS (# or .)
  3.  action()  is the action to be performed on the element(s)
  4. The semicolon (;) is used to close the action

For example, to add a class in jQuery, we can use the jQuery ...

Get Practical Web Design 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.