jquery gets the node name

  • 2020-06-01 08:21:00
  • OfStack

The get(index) method of jQuery allows you to select an actual DOM element and manipulate it directly, rather than through the jQuery function, and then access the tagName attribute of the DOM element directly. $(this).get(0) is equivalent to $(this)[0].

As follows

<input id="test" type="text" name="xxx" value="xxx">

Get the DIV(note the uppercase)

How does jquery get the name of an element on 1, for example

$(" # aa "). xxxmethod get "div"
How does jquery get the name of an element such as

$(" # aa "). xxxmethod get "div"

$("#aa")[0].tagName is fine
jQuery gets the tag name


Get the tag name capitalized here, such as :A, DIV


Conversion of jQuery objects to dom objects

Only jquery objects can use the methods defined by jquery. Note that there is a difference between the dom object and the jquery object. When calling a method, you should pay attention to whether you are manipulating the dom object or the jquery object.
Normal dom object 1 can be converted to jquery object by $().
If: $(document.getElementByIdx_x ("msg")) is an jquery object, you can use the jquery method.

Because the jquery object itself is a collection. So if an jquery object is to be converted to an dom object, one of its items must be fetched, usually by index.
For example: $("#msg")[0], $("div").eq(1)[0], $("div").get()[1], $("td")[5] these are dom objects that can be used using the method in dom, but can no longer use the Jquery method.

The following are all correct:

$("#msg").get(0).innerHTML; -

That's all for this article, I hope you enjoy it.

Related articles: