Multiple Attribute [attr="value"][attrn="valuen"]
S2C Home « Selectors « Multiple Attribute [attr="value"][attrn="valuen"]
Multiple attribute match selector.
Shorthand version $('[attr="value"][attrn="valuen"]')
Description
The [attr="value"][attrn="valuen"]
selector, selects all elements that match all of the specified attribute and value filters
Syntax
Signature | Description |
---|---|
jQuery('[attr="value"][attrn="valuen"]') | Multiple Attribute match |
Parameters
Parameter | Description |
---|---|
attr | The attribute name. |
value | The optional attribute value which can be either an unquoted single word or a quoted string. |
attrn | As many more attribute names as required. |
valuen | As many more optional attribute values as required. |
Return
N/A.
Multiple Attribute [attr="value"][attrn="valuen"]
Examples Top
Selects all elements that match all of the specified attribute and value filters.
The following example will select 'a' elements with a 'href' attribute of '#multiattrb' that contain a 'span' element with a class of 'ital' and turn the background colour yellow.
$(function(){
$('#btn1').on('click', function() {
$('a[href="#multiattrb"] span[class="ital"]')
.css('backgroundColor', 'yellow');
});
});
The following example will select left sidebar elements that contain a 'link' element with a 'href' attribute that starts with 's' and turn the background colour silver.
$(function(){
$('#btn2').on('click', function() {
$('div[id="sidebarleft"] a[href^="s"]')
.css('backgroundColor', 'silver');
});
});
The following example will select 'ul' elements with an id of 'fb' that contain a 'link' element with a 'href' attribute that starts with 'last' and turn the background colour orange.
$(function(){
$('#btn3').on('click', function() {
$('ul[id="fb"] a[href^="attrib"]')
.css('backgroundColor', 'orange');
});
});