Home >Web Front-end >JS Tutorial >jQuery gets DOM node instance analysis (2 ways)_jquery

jQuery gets DOM node instance analysis (2 ways)_jquery

WBOY
WBOYOriginal
2016-05-16 15:25:411267browse

The example in this article describes how to obtain DOM nodes with jQuery. Share it with everyone for your reference, the details are as follows:

The wrapped DOM object in jQuery is actually an array. There are two ways to obtain a pure DOM object:

1. Use array index to access , for example:

Copy code The code is as follows:
var dom = $(dom)[0];

2. Use the function get() to access , for example:

Copy code The code is as follows:
var dom = $(dom).get(0);

The parameter in the get() function is the index number.

3. Example

var div = document.createElement("DIV");
div.innerText = "TEST IS OK!";
document.body.appendChild(div);
var $tmp = $(div);
alert($tmp[0].innerText); //方式1获取DOM节点对象
alert($tmp.get(0).innerText); //方式2获取DOM节点对象

I hope this article will be helpful to everyone in jQuery programming.

Statement:
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