In this post, we are learning about
jQuery to Check the Type of
Matched Elements Selector.
jQuery jQuery allows we check the
type of matched elements with the
is( ) function. This function can be useful when we have matched a
whole set of elements, but we want to work with only
one particular type of matched elements: for example,
<p> elements.To use the
is( ) function, we write code like this:
This selector returns true if the element with ID p1 is a <p> element.
Below code example puts for see above jQuery to Check the Type of Matched Elements Selector working.
jqscript.html
<html>
<head>
<title>
Checking the types of matches
</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
function checkType( )
{
if($('#p2').is('p')){
alert("The element with ID p2 is a <p> element");
}
}
</script>
</head>
<body>
<h1>Checking the types of matches</h1>
<div>
<p id="p1">This is paragraph 1.</p>
<p id="p2">यह पैरा 2 है.</p>
<p id="p3">हा परिच्छेद 3 आहे.</p>
<p id="p4">This is paragraph 4.</p>
</div>
<form>
<input type="button"
value="Select"
onclick="checkType()"
</input>
</form>
</body>
</html>
Output:
No comments:
Post a Comment
Please do not enter any spam link in the comment box.