Home >Web Front-end >JS Tutorial >jquery gets node name_jquery
jQuery's get(index) method allows you to select an actual DOM element and operate on it directly instead of going through a jQuery function, and then directly access the tagName attribute of the DOM element. $(this).get(0) is equivalent to $(this)[0].
Such as the following elements
What is obtained is DIV (note that it is capitalized)
How to get the name of an element in jquery, such as
dd
$("#aa").xxxmethod gets "div"
How to get the name of an element in jquery such as
dd
$("#aa").xxxmethod gets "div"
$('#elementId').get(0).tagName
$("#aa")[0].tagName That’s it
jQuery gets tag name
Here you get the tag name in capital letters, such as: A, DIV
Background knowledge:
Conversion between jQuery object and dom object
Only jquery objects can use the methods defined by jquery. Note that there is a difference between dom objects and jquery objects. When calling methods, you should pay attention to whether you are operating on dom objects or jquery objects.
Ordinary DOM objects can generally be converted into jQuery objects through $().
For example: $(document.getElementByIdx_x("msg")) is a jquery object, and you can use jquery methods.
Because the jquery object itself is a collection. Therefore, if the jquery object is to be converted into a dom object, one of the items must be retrieved, which can generally be retrieved through an index.
For example: $("#msg")[0], $("div").eq(1)[0], $("div").get()[1], $("td")[5 ] These are dom objects, and you can use methods in dom, but you can no longer use Jquery methods.
The following ways of writing are all correct:
The above is the entire content of this article, I hope you all like it.