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

154
Views
How to show <p> tag in <ul> tag?

I have a <ul> tag that contain 2 <li> tag with a <p> tag that contain text:

<ul>
    <li>List-item-1<p>para-1</p></li>
    <li>List-item-2<p>para-2</p></li>
</ul>

I want to remove List-item-1 and List-item-2 from the code. I tried this:

$('li').each(function () {
    $('li').html($('p'));
});

But I am getting output as below:

  • para-1

para-2

para-1

para-2

  • para-1

para-2

para-1

para-2

How do I get output with <p> tag only?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can use find() function here.

$('ul li').html(function(){
  return $(this).find('p');
});
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<ul>
    <li>List-item-1<p>para-1</p></li>
    <li>List-item-2<p>para-2</p></li>
</ul>

about 4 years ago · Juan Pablo Isaza Report

0

You can replace innerText even without jQuery.

document.querySelectorAll('li').forEach(li => {
  li.innerText = li.querySelector('p').innerText
})
<ul>
    <li>List-item-1<p>para-1</p></li>
    <li>List-item-2<p>para-2</p></li>
</ul>

about 4 years ago · Juan Pablo Isaza Report

0

You can also remove the text.

$('ul li').each((i,ele) => {
  ele.firstChild.remove()
})
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<ul>
  <li>List-item-1
    <p>para-1</p>
  </li>
  <li>List-item-2
    <p>para-2</p>
  </li>
</ul>

about 4 years ago · Juan Pablo Isaza Report
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!