且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

javascript中的querySelector()和querySelectorAll()

更新时间:2022-06-30 09:25:37

//get the header ID element

document.querySelector("#header");


//get the first element with a dropcap class

document.querySelector(".dropcap");


//get all the paragraphs with a "dropcap" class produces a nodelist

document.querySelectorAll(".dropcap");


//get all elements with a class of "dropcap" or "huge"

document .querySelectorAll(".dropcap,.huge");


//get all paragraphs that hava a class

document.querySelectorAll("p[class]");


浏览器支持度

IE 8.0及以上
Firefox 3.5及以上
chrome 1及更高
opera 10及更高
Safari 3.2及更高