Has Attribute Selector [name] in JQuery



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

  • attribute
    An attribute name.


Bind a single click that adds the div id to its text.

<!DOCTYPE html>
  <script src="/scripts/jquery-1.4.js"></script>
	<div>no id</div>
  <div id="hey">with id</div>

  <div id="there">has an id</div>

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

Leave a Reply

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