Has Attribute Selector [name]
Selects elements that have the specified attribute, with any value.
.attributeHas(attribute)
attribute
| String | An attribute name. |
Bind a single click to divs with an id that adds the id to the div's text.
JS
<div>no id</div>
<div id="hey">with id</div>
<div id="there">has an id</div>
<div>nope</div>
HTML
// Using .one() so the handler is executed at most once
// per element per event type
$("div[id]").one("click", function () {
var idString = $(this).text() + " = " + $(this).attr("id");
$(this).text(idString);
});
DEMO