jQuery Tutorial
$("#idName").is("p");
'is' function is used to check an particular element to see the particular 'tag' element.
here element having id 'idPage' is to check whether 'p' (paragraph) element.
here used id to access the element, element can also be accessed with other selectors using class name and other attributes.
This example is based on class name 'className' to match the element and checks the matching element tag is p, div or span.
function checkTag() { var isParagraph = $(".className").is("p"); var isDiv= $(".className").is("div"); var isSpan= $(".className").is("span"); alert("Matching element: "+ "paragraph: "+isParagraph +" div: "+isDiv+" span: "+isSpan); }
<html> <head> <title>The jQuery Example - To check </title> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script type = "text/javascript"> function checkTag() { var isParagraph = $("#idPage").is("p"); var isDiv= $("#idPage").is("div"); var isSpan= $("#idPage").is("span"); alert("Matching element: "+ "paragraph: "+isParagraph +" div: "+isDiv+" span: "+isSpan); } </script> </head> <body> <div>This is div</div> <p id="idPage">This is paragraph</p> <span>This is span.</p> <input type="button" value="Get Tag" onclick="checkTag();"/> </body> </html>Output:
checks whether element having id 'idPage' is div tag.
$("#idPage").is("div");
checks whether element having id 'idPage' is span tag.
$("#idPage").is("span");
On clicking of 'Get Tag' button, display the element is whether p, div or span tag.
« Previous Next » jQuery Tutorial
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us
| Report website issues in Github
| Facebook page
| Google+ page