javaScript in querySelector and querySelectorAll

querySelector and querySelectorAll are new W3C provides a query interface, the main features are as follows:

1, querySelector only return the first matching element, if there is no match, it returns null. 
2, querySelectorAll returned set of matched elements, if there is no match, return an empty NodeList (node array). 
3, the result returned is static, after changes to the structure of the document will not affect the result to take before. 
 
These two methods can accept three types of parameters: id (#), class, tag, like jquery selector (.).
 
document.querySelector obj = var ( "ID #");
var obj = document.querySelector ( "className.");
var obj = document.querySelector ( "div");
var document.body.querySelector EL = ( "style [ = type 'text / CSS'], style: Not ([type]) ");
var = document.querySelectorAll Elements (" # Score> tbody> TR> TD: Nth-of-type (2) ");
var Elements = document.querySelectorAll ( "# id1, # id2, .class1, class2, div a, #list li img");
Note:


Currently IE8 +, ff, chrome support this api

original link: https: //blog.csdn.net/weixin_42160828/article/details/80634520

Guess you like

Origin www.cnblogs.com/isme-zjh/p/11547418.html