I have this code:
var parent = links[i].parentNode;
I’d like to write something like:
if (parent.typeOfElement == "div") {
...
}
How can I do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use
.tagName, which is (for elements) the same as.nodeName.So:
Note that the tag name is supposed to be returned in uppercase for HTML, but in XML (including xhtml) it is supposed to preserve the original case – which for xhtml means it should be lowercase. To be safe, and allow for any future changes to your document type and allow for non-standard browser behaviour you might want to convert to all upper or all lower:
In my experience
.tagNameis used much more often, but I gather that some consider.nodeNamea better choice because it works for attributes (and more) as well as elements.