<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>