How to get < span> value?

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

    You need to change your code as below:-

    <html>
    <body>
    
    <span id="span_Id">Click the button to display the content.</span>
    
    <button onclick="displayDate()">Click Me</button>
    
    <script>
    function displayDate() {
       var span_Text = document.getElementById("span_Id").innerText;
       alert (span_Text);
    }
    </script>
    </body>
    </html>
    

    After doing this you will get the tag value in alert.

    0 讨论(0)
提交回复
热议问题