Home > Web Front-end > JS Tutorial > jquery gets node name_jquery

jquery gets node name_jquery

WBOY
Release: 2016-05-16 16:02:13
Original
1909 people have browsed it

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

Copy code The code is as follows:


$("#test")[0].tagName

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

Copy code The code is as follows:

$('#elementId').get(0).tagName

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:

Copy code The code is as follows:

$("#msg").html();
$("#msg")[0].innerHTML;
$("#msg").eq(0)[0].innerHTML;
$("#msg").get(0).innerHTML; -

The above is the entire content of this article, I hope you all like it.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template