In this post, we are learning about
jQuery Select Elements by
Attribute Value selector.
jQuery allows we select page
elements based not only on whether the
element has a
certain attribute, but also on the
attribute's value.
To select elements based on their
attribute values, use below selector.
where attribute is the attribute we are searching for, and value is the value we want
the attribute to hold.
For example, to match <p> elements with the language attribute set to 'Hindi', use below selector:
Below code example puts for see above jQuery selecting elements by attribute value selector working.
jqscript.html
<html>
<head>
<title>
Selecting elements by
attribute value
</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
function setStyle() {
$('p[language="Hindi"]').css("font-style", "italic");
}
</script>
</head>
<body>
<h1>
Selecting elements by attribute
value
</h1>
<div>
<p>This is paragraph 1.</p>
<p language="Hindi">यह पैरा 2 है.</p>
<p language="Marathi">हा परिच्छेद 3 आहे.</p>
<p >This is paragraph 4.</p>
</div>
<form>
<input type="button"
value="Select"
onclick="setStyle()"
</input>
</form>
</body>
</html>
Output:
No comments:
Post a Comment
Please do not enter any spam link in the comment box.