jquery select all DOM elements
In this topic, we will see how to select all DOM elements in jquery with example.
Select All DOM Elements:-
In some cases, we need to select all DOM elements or other elements. You can select every element on a page by using the * character (wildcard selector). The wildcard is wrapped in quotes between the parentheses directly after the $ sign ($(‘*’)). When you pass wildcard (*) selector to the jquery(‘*’ ) function or the $(‘*’) function, which is the same thing, you select all DOM elements. In general, it’s practical to use the * selector when you want to assign a CSS style or an attribute to every element on a page.
Select All DOM Elements – Example 1
In the following example, we select all the elements on the page with the wildcard selector and add a CSS border to each element. To add a CSS border, we use the method .css(‘border’,’1px solid #333′);.
Output
$(‘*’).css(‘border’,’1px solid #333′); This line tells jquery to select all DOM elements and set the css(‘border’,’1px solid #333′); CSS style.
Select All DOM Elements – Example 2
In the following example, we will see how to check all the Checkboxes using $(‘*’).attr(‘checked’,’checked’);OutPut:-
Post A Comment:
0 comments: