<div id="divs"> <p>one text1</p> <p>two text</p> <p>three text</p> <p>one text2</p> <p>fife text</p> <p>Six text</p> </div> <script> document.querySelectorAll('#divs > p').forEach(el=>{ if(/one/.test(el.textContent)) console.log(el); }); </script>
var els = document.querySelectorAll('#divs > p'); for (var i = 0; i < els.length; i++){ if (/one/.test(els[i].textContent)) console.log(els[i]); }