In this post, we are learning about
jQuery To select elements with specific text selector.
jQuery allows we further refine our search for particular elements by requesting elements containing
specific text. We can not
easily perform this same task using the same
JavaScript in
multiple browsers, so
jQuery saves we a lot of time here.To select elements containing particular text, use the selector.
where text is the text we are searching for.
For example, to match the <p> element that contains the text "3" (as in "This is paragraph 3"), use this selector:
Below code example puts for see above jQuery To select elements with specific text selector working.
jqscript.html
<html>
<head>
<title>
Selecting elements by
contained text
</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
function setStyle() {
$('p:contains("3")').css("font-style", "italic");
}
</script>
</head>
<body>
<h1>
Selecting elements by contained
text
</h1>
<div>
<p>This is paragraph 1.</p>
<p>This is paragraph 2.</p>
<p>This is paragraph 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.