Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

224
Views
P tag problem while getting all html contents included div in a span element

I need to get all html contents in the span element containing the test class name. But I can't get this content if it is inside the p tag.

let content = document.querySelectorAll('span.test');
for (i = 0; i < content.length; i++)
{
alert("CONTENT: "+content[i].innerHTML);
}
<span class="test">normaltext1<span>spantext</span>normaltext2<div>divtext</div>normaltext3</span>

This code working but when I added p tag to content (to first and last ) this code didn't worked.

let content = document.querySelectorAll('span.test');
for (i = 0; i < content.length; i++)
{
alert("CONTENT: "+content[i].innerHTML);
}
<p><span class="test">normaltext1<span>spantext</span>normaltext2<div><div>divtext</div>normaltext3</span></p>

Result is : CONTENT: normaltext1<span>spantext</span>normaltext2 Content starting with div is not coming after normaltext2

jsFiddle Link: https://jsfiddle.net/106gy4hs/

How can I do this?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!