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();
- The $ sign starts any jQuery action
- The (selector) is used to query (or find) HTML elements, by ID or class like in CSS (# or .)
- action() is the action to be performed on the element(s)
- The semicolon (;) is used to close the action
For example, to add a class in jQuery, we can use the jQuery ...