tadam logo
Did you find an error in the text?
Select this with mouse and press
Ctrl + Enter
Xhtml.co.il Check Spelling
Orphus system

[attribute]

Has Attribute Selector [attribute]

Arguments

jQuery('[attribute]')

version added: 1.0
attribute
An attribute name.

Description: Selects elements that have the specified attribute, with any value.

Examples

Example 1

Bind a single click that adds the div id to its text.
    $("div[id]").one("click", function(){
      var idString = $(this).text() + " = " + $(this).attr("id");
      $(this).text(idString);
    });

The output of the code above will be:
Full source:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<script src="http://code.jquery.com/jquery-latest.js"></script>
  
  <script>

  $(document).ready(function(){
    
    $("div[id]").one("click", function(){
      var idString = $(this).text() + " = " + $(this).attr("id");
      $(this).text(idString);
    });

  });
  </script>

  
</head>
<body>

  <div>no id</div>
  <div id="hey">with id</div>
  <div id="there">has an id</div>

  <div>nope</div>

</body>
</html>
Was this information helpful?
   

Comments