In this tutorial you will learn about the jQuery Syntax and its application with practical example.
With jQuery statement we usually select (query) HTML elements and perform certain actions on them. jQuery statements are very quick and efficient for selecting and performing actions on any HTML element.
Syntax:-
1 |
$(selector).action(); |
JQuery statement typically begins with a dollar sign ($) and ends with a semicolon (;). Above is the general syntax of a jQuery statement, here –
$ :- A dollar sign ($
) is just an alias to define/access jQuery.
(selector) :- A (selector) to select or access HTML elements from DOM.
action() :- It represents an action to be performed on the selected element(s).
1 |
$(this).css('border','3px solid black'); |
It applies border to the current element.
1 |
$('p').css('border','3px solid black'); |
It applies border to all <p> elements.
1 |
$('.example').css('border','3px solid black'); |
It applies border to all elements with class=”example”.
1 |
$('#example').css('border','3px solid black'); |
It applies border to the element with id=”example”.