How do I change the text of a span element using JavaScript?

后端 未结 13 866
悲&欢浪女
悲&欢浪女 2020-11-22 09:21

If I have a span, say:

 hereismytext 

How do I use JavaScript to change "hereism

13条回答
  •  無奈伤痛
    2020-11-22 09:58

    You may also use the querySelector() method, assuming the 'myspan' id is unique as the method returns the first element with the specified selector:

    document.querySelector('#myspan').textContent = 'newtext';
    

    developer.mozilla

提交回复
热议问题