How to get < span> value?

前端 未结 7 2067
温柔的废话
温柔的废话 2021-02-07 10:41

There are a piece of code,but can not use tag.

So,how do I get to the 1 2 3 4?

7条回答
  •  情深已故
    2021-02-07 11:32

    You can use querySelectorAll to get all span elements and then use new ES2015 (ES6) spread operator convert StaticNodeList that querySelectorAll returns to array of spans, and then use map operator to get list of items.

    See example bellow

    ([...document.querySelectorAll('#test span')]).map(x => console.log(x.innerHTML))
    1 2 3 4

提交回复
热议问题