Home > Web Front-end > JS Tutorial > Summary of methods for finding nodes in js_javascript skills

Summary of methods for finding nodes in js_javascript skills

WBOY
Release: 2016-05-16 16:20:43
Original
1404 people have browsed it

The example in this article summarizes the method of finding nodes in js. Share it with everyone for your reference. The specific analysis is as follows:

Here are three ways to find nodes:

1. Search based on id, the return value is an object:

Copy code The code is as follows:
document.getElementById( );

2. Search based on html tags such as div/p/.... and return an array (actually also an object)
Copy the code The code is as follows:
document.getElementsByTagName();

3. Use it in the form and search for
document.getElementsByName();

Special note: At present, some browsers have extended getElementsByName to other element nodes, that is, if div/p... and other tags have a name attribute, they can also be used; however, IE browsers can only be used in forms. Therefore, to maintain compatibility, it should only be used within forms.

I hope this article will be helpful to everyone’s JavaScript programming design.

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