jQuery API

Attribute Equals Selector [name=value]

attributeEquals selector

version added: 1.0jQuery('[attribute=value]')

  • attribute
    An attribute name.
    value
    An attribute value. Quotes are optional.

Description: Selects elements that have the specified attribute with a value exactly equal to a certain value.

Example:

Finds all inputs with name 'newsletter' and changes the text of the span next to it.

<!DOCTYPE html>
<html>
<head>
  <script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
	<div>

    <input type="radio" name="newsletter" value="Hot Fuzz" />
    <span>name?</span>

  </div>
  <div>
    <input type="radio" name="newsletters" value="Cold Fusion" />

    <span>name?</span>
  </div>
  <div>
    <input type="radio" name="accept" value="Evil Plans" />

    <span>name?</span>
  </div>
<script>$("input[name='newsletter']").next().text(" is newsletter");</script>
</body>
</html>

Demo:

Comments

  • Support requests, bug reports, and off-topic comments will be deleted without warning.

  • Please do post corrections or additional examples for Attribute Equals Selector [name=value] below. We aim to quickly move corrections into the documentation.
  • If you need help, post at the forums or in the #jquery IRC channel.
  • Report bugs on the bug tracker or the jQuery Forum.
  • Discussions about the API specifically should be addressed in the Developing jQuery Core forum.
  • Hi Karl, for any attribute selector is needed @?

    I probe the selector $('input[@name='myInput']').click ... but problem I see is to by clicking on any input triggers the event associated with this selector, but without the @ works normal

    this behavior is normal?

    sorry for my english.-
  • MrFussyfont
    Attribute selectors may be buggy in older versions of jQuery. I'm stuck with version 1.1.4 and input[type=hidden] does not work. No, I can't use input:hidden because that also selects inputs of other types that are not visible.
  • The API changed after 1.1.4 for attribute selectors. For 1.1.4 and below, you need to include the @ symbol. So, your example would look like this:

    $('input[@type=hidden]')