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

Exact match selector.

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


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 (-).


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


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



Attribute Equals [attr="value"] ExampleTop

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).

  $('#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: