html - Append data within a class using pure Javascript -
i want append text within class using javascript, not using jquery. example:
<div class="a"> <div class ="b"> <div class="c"> </div> </div> <div>
after putting text within class="b"
, should like:
<div class="a"> <div class ="b"> text <div class="c"> </div> </div> <div>
i want without using jquery.
using insertadjacenthtml()
method:
var elements = document.getelementsbyclassname("b"); // elements class 'b' (var = 0; < elements.length; i++) { // every element class 'b': elements[i].insertadjacenthtml("afterbegin", "this text"); // insert text inside element }
<div class="a"> <div class="b"><!-- text inserted here --> <div class="c"> </div> </div> <div>
Comments
Post a Comment