Attribute Equals [attr="value"]S2C Home « Selectors « Attribute Equals [attr="value"]

Exact match selector.

Shorthand version  $('[attr="value"]')

Description

The [attr="value"] selector, selects all elements with the specified attribute name and a value equal to the specified string or prefixed with that string followed by a hyphen (-).

Syntax


Signature Description
jQuery('[attr="value"]')Exact match

Parameters


Parameter Description
attrThe attribute name.
valueThe attribute value which can be either an unquoted single word or a quoted string.

Return

N/A.

Attribute Equals [attr="value"] Examplego to top of page Top

Selects all elements that have the specified attribute name with a value exactly equal to the specified value.

The following example will select 'input' elements on the page that have a value attribute containing the values 'btn5: Turn Orange' or 'btn6: Turn Yellow' and change their background color to orange or yellow respectively (look at the two buttons below).


$(function(){
  $('#btn5').on('click', function() {
    $('input[value="btn5: Turn Orange"]').css('backgroundColor', 'orange');
  });
  $('#btn6').on('click', function() {
    $('input[value="btn5: Turn Yellow"]').css('backgroundColor', 'yellow');
  });
}); 

Press the buttons below to action the above code:

            


go to home page Homepage go to top of page Top