Element ('element')
S2C Home « Selectors « Element ('element')
Element selector.
Shorthand version $('element')
Description
The ('element')
selector, selects all elements that have the specified tag name.
- When used this method calls the JavaScript
getElementsByTagName()
function 'under the hood' to return the appropriate elements.
Syntax
Signature | Description |
---|---|
jQuery('element') | Element match |
Parameters
Parameter | Description |
---|---|
element | An element to search for (this refers to the tagName of DOM nodes). |
Return
N/A.
Element ('element')
ExampleTop
Selects all elements that have the specified tag name.
The following example will select all 'i' elements and change the text colour of these elements to green.
$(function(){
$('#btn1').on('click', function() {
$('i').css('color', 'green');
});
});
The following example will select all 'code' elements and change the background colour of these elements to yellow.
$(function(){
$('#btn2').on('click', function() {
$('code').css('backgroundColor', 'yellow');
});
});
The following example will select all 'form' elements and change background text colour of these elements to orange.
$(function(){
$('#btn3').on('click', function() {
$('form').css('backgroundColor', 'orange');
});
});