Home  >  Article  >  Web Front-end  >  What are the methods for positioning elements in JavaScript?

What are the methods for positioning elements in JavaScript?

WBOY
WBOYOriginal
2021-12-28 18:19:455783browse

Methods to locate elements: 1. Use getElementById("id"); 2. Use "name"; 3. Use "element tag name"; 4. Use "class"; 5. Use "css selection" device".

What are the methods for positioning elements in JavaScript?

The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.

What are the methods for locating elements in JavaScript

Except for the id, which locates a single element element object, everything else is returned by elements. It is a list object

  • 1. Get by id

document.getElementById(“id”)

  • 2. Get by name

document.getElementsByName(“Name”)

returns list

  • 3 .Select elements by tag name

document.getElementsByTagName(“tag”)

  • 4.Select elements by CLASS class

document.getElementsByClassName("class")

Compatibility: IE8 and below browsers do not implement the getElementsByClassName method

  • 5. Select elements through CSS selectors

document.querySelectorAll("css selector")

[Related recommendations: javascript learning tutorial]

The above is the detailed content of What are the methods for positioning elements in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

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