jQuery Selector :- jQuery selector work as a CSS selector . CSS selector is used to add style to the HTML Page while jQuery selector is used to add behaviors to the HTML Page.
Selecting Elements by JavaScript | Selecting Elements by jQuery |
document.getElementsByTagName(“p”)[0].innerHTML = “Change the page.”; | $(“p”).html(“Change the page.”); |
for (i = 0; i <= 4; i++){document.getElementsByTagName(“p”)[i].innerHTML=”Change the page”; } | $(“p”).html(“Change the page.”); |
What is “$” sign means in jQuery?
“$” is not other than “jQuery”. It is symbolic notation of “jQuery” word.
CSS Selector | jQuery Selector |
h1 {text-align: left ;} – Selection by Element. | $(“h1”).append () – Selection by Element. |
.my_class{position: absolute;} – By Class | $(“.my_class”).append() – By Class |
#my_id {color: #3300FF;} – By ID | $(“#my_id”).append() – By ID |
Example:-
- $(“div”).remove () – This will give all the div on the page.
- $(“#Id_name”) .remove () – This will give the DOM element having id mentioned.
- $(“.class_name”) .remove () – This will give the entire DOM element using class mentioned.
- $(“div.class_name”) .remove () – This will give all the div using this class on the page.
- $(“div div img”) .remove () – This will select the images under div which is in another div.
Special Selector
$(this) .remove () – It will select the current element “Current Element”. It’s meaning change throughout the code.