score:1

Accepted answer

I would have done such a task with plain Javascript and not involved an external library.

But if it has to be done using D3:

d3.selectAll('.newfield h2')
  .text("somestring")
  //.append("br") //not really necessary!
<script src="https://d3js.org/d3.v5.min.js"></script>
<div class="newfield col-sm-4">
  <h2>42</h2>
  <h3>Appending above</h3>
</div>


Related Query

More Query from same tag