Attribute existence([attr])
In this chapter you will learn:
Description and Syntax
$('[attr]')
selects all elements that have the attr
attribute, with any value.
Examples
Selector | Selects |
---|---|
$('[rel]') | all elements that have a rel attribute |
$('.myclass[style]') | all elements with the class myclass that have a style attribute |
The following code selects elements with id
attribute.
<html><!-- j a va2s . co m-->
<head>
<script src="http://java2s.com/style/jquery-1.8.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("div[id]").one("click", function(){
var idString = $(this).text() + " = " + $(this).attr("id");
$(this).text(idString);
});
});
</script>
</head>
<body>
Click to see.
<div>div</div>
<div id="hey">div</div>
</body>
</html>
Next chapter...
What you will learn in the next chapter:
- Description and Syntax for attribute equals selector
- Examples for attribute equals selector
- How to use two attribute selectors together