How to get < span> value?

前端 未结 7 2063
温柔的废话
温柔的废话 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:19

    No jQuery tag, so I'm assuming pure JavaScript

    var spanText = document.getElementById('targetSpanId').innerText;
    

    Is what you need

    But in your case:

    var spans = document.getElementById('test').getElementsByTagName('span');//returns node-list of spans
    for (var i=0;i

    Here's a fiddle

提交回复
热议问题