All ('*')
S2C Home « Selectors « All ('*')
All selector.
Shorthand version $('*')
Description
The ('*')
selector allows us to select all elements.
- The 'All' selector is also commonly known as the 'Universal' selector.
- Traverses all elements and so is extremely slow unless used on its own.
Syntax
Signature | Description |
---|---|
jQuery('*') | Select all elements. |
Parameters
None.
Return
N/A.
All Selector ('*')
ExampleTop
Select all elements.
The following example will select every element on the page and change the visible text to indigo.
$(function(){
$('#btn1').on('click', function() {
$('*').css('color', 'indigo');
});
});
The following example will select every element on the page and change the background colour to silver.
$(function(){
$('#btn2').on('click', function() {
$('*').css('backgroundColor', 'silver');
});
});
The following example will select every element on the page and 1px black border around it.
$(function(){
$('#btn3').on('click', function() {
$('*').css('border', '1px solid black');
});
});