Best way to find DOM elements with css selectors

后端 未结 5 844
感情败类
感情败类 2020-11-29 06:19

What\'s the easiest way to find Dom elements with a css selector, without using a library?

function select( selector ) {
 return [ /* some magic here please          


        
5条回答
  •  时光说笑
    2020-11-29 06:37

    In addition to the custom hacks, in recent browsers you can use the native methods defined in the W3C Selectors API Level 1, namely document.querySelector() and document.querySelectorAll():

    var cells = document.querySelectorAll("#score > tbody > tr > td:nth-of-type(2)");
    

提交回复
热议问题