Get All Elements in an HTML document with a specific CSS Class

前端 未结 10 887
时光取名叫无心
时光取名叫无心 2020-12-01 04:10

What\'s the best way to get an array of all elements in an html document with a specific CSS class using javascript?

No javascript frameworks like jQuery allowed her

10条回答
  •  情歌与酒
    2020-12-01 05:00

    1) Get all elements in the document (document.getElementsByTagName('*'))
    2) Do a regular expression match on the element's className attribute for each element

提交回复
热议问题