JavaScript DOM manipulation <1>

HTML DOM method is an action that you can (on the HTML element) execution.

HTML DOM attribute is the value you can set or change the HTML element.

innerHTML property

The easiest way to get element's content is innerHTML property.

innerHTML property or alternatively may be used to obtain the content of HTML elements.

innerHTML property can be used to obtain or alter any HTML elements, and comprising a.

<p id="demo"></p>


Find and access the HTML element in an HTML page.

Finding HTML elements by id

var myElement = document.getElementById("intro");

Finding HTML elements by tag name

var x = document.getElementsByTagName("p");
This example finds id = "main" element, then look "main" all

Elements:
Examples

var x = document.getElementById("main");
var y = x.getElementsByTagName("p"); 
document.getElementsByClassName(name)   

To find elements by class name

var x = document.getElementsByClassName("intro");

Find HTML elements through CSS selectors

The present example returns class = "intro" all

List of elements:

Examples

var x = document.querySelectorAll("p.intro");

Guess you like

Origin www.cnblogs.com/faramita/p/11316461.html