简体   繁体   中英

Replace all the text in a div with class name - only js

I'm trying to all the text in a div by class name:

<div class="something...">

And then replace the text with something. No, i don't want to use jquery.

Should be straight forward

 var elements = document.querySelectorAll('.something'); for ( var i=elements.length; i--; ) { elements[i].textContent = "something else"; } 
 <div class="something">Soft</div> <br> <div class="something">Kitty</div> <br> <div class="something">Warm</div> <br> <div class="something">Kitty</div> <br> <span class="something" style="color:green">Little ball of fur ...</span> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM