chaining getElementById

前端 未结 6 1700
盖世英雄少女心
盖世英雄少女心 2020-11-29 12:27

I\'ve been looking for an answer to this question but I could find none so I thought I\'d try StackOverflow.

In javascript, is this valid:

x = document

6条回答
  •  Happy的楠姐
    2020-11-29 12:55

    Consider not using id when there are more than one

    Maybe a class or custom attribute is better, you can then use document.querySelectorAll to fins them.

    els = document.querySelectorAll('[custom-attr]')
    

提交回复
热议问题