Home > Web Front-end > JS Tutorial > body text

JavaScript gets the code of an element on the page_javascript tips

WBOY
Release: 2016-05-16 18:09:27
Original
1091 people have browsed it

The syntax recommended by W3C standards is to obtain an element in the DOM tree through the document document object. Common methods include getElementById(), getElementsByName(), and getElementsByTagName(). Their functions are through the id attribute and name attribute/tag name respectively. Returns a single node or collection of nodes.

Copy code The code is as follows:

.org/1999/xhtml">


JavaScript method of getting an element on the page


Here is the head


Click on the header to pop up the content of myHeader

























When click:

, pop up:

When click:

, pop up:

When click:

, pop up:

Especially in the following code,


Copy the code The code is as follows:
function getValue (){
var x=document.getElementById("myHeader");
alert(x.innerHTML);
}

involves a knowledge point: HTML DOM innerHTML , the function is all the content from the starting position to the ending position of the object, including the Html tag
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