javascript dom find elements common method

1. Find by id

document.getElementById();

Support: All major browsers

 

2. Find by label name

document.getElementsByTagName (); // tag name; Elements plus S, it is selected from an array of classes;

Support: All major browsers

 

3. Find by name property

document.getElementsByName (); // name attribute, the label may be part; Elements plus S, it is selected from an array of classes;

Support: All major browsers

 

4. Find by class property

document.getElementsByClassName (); // class; Elements plus S, it is selected from the class of the array; IE9 does not support the following;

Support: IE9 +

 

5.1 Press selector selects (return document that match a specified selector element)

document.querySelector();

Support: IE8 +

 

5.2 Press selector to select (Back to return all elements)

document.querySelectorAll() 

Support: IE8 +

 

5.3 selector parameter (CSS selectors: https://www.runoob.com/cssref/css-selectors.html )

parameter Types of description
CSS selectors String

have to. Specify one or more matching elements CSS selectors. Thereof may be used id, class, type, attributes, attribute values, etc. to select elements.

A plurality of selectors, separated by commas, returns a matching element.

Guess you like

Origin www.cnblogs.com/wuanyun/p/11141896.html