Skip to content Skip to sidebar Skip to footer

How To Select All Text Nodes After Specific Element

HTML:

First

Second
Third Fourth &

Solution 1:

You can get the content and use split with hr to get the html after the hr and then replace this content within a div and you will be able to manipulate this div to get your content:

var content = document.querySelector('.someclass').innerHTML;
content = content.split('<hr>');
content = content[1];

document.querySelector('.hide').innerHTML = content;
/**/var nodes = document.querySelector('.hide').childNodes;
for (var i = 0; i < nodes.length; i++) {
  console.log(nodes[i].textContent);
}
.hide {
  display: none;
}
<divclass="someclass"><h3>First</h3><strong>Second</strong><hr> Third
  <br> Fourth
  <br><em></em> ...
</div><divclass="hide"></div>

Post a Comment for "How To Select All Text Nodes After Specific Element"