Attribute Equals Selector [name=value] in JQuery

 

Sample:

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

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

Example:

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

<!DOCTYPE html>
<html>
<head>
  <script src="/scripts/jquery-1.4.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>

Leave a Reply

Your email address will not be published. Required fields are marked *