What is the difference between $('this')[0].nodeName
and $('this')[0].tagName
?
The tagName
property is meant specifically for element nodes (type 1 nodes) to get the type of element.
There are several other types of nodes as well (comment, attribute, text, etc.). To get the name of any of the various node types, you can use the nodeName
property.
When using nodeName
against an element node, you'll get its tag name, so either could really be used, though you'll get better consistency between browsers when using nodeName
.