Delete an element of a specified div

0

It has the following code in html:

<div id="lista">
   <p>Antonio Carlos Almeida Filhos</p>         
</div>

How could I exclude this paragraph only from this div without deleting other paragraphs on the page. We can use $("p").remove() , but in that case you would be removing all the paragraphs on the page.

    
asked by anonymous 29.11.2017 / 13:54

2 answers

3

Friend, you can use the css selectors in the same way in javascript. So you can select only the chosen element.

$("#lista p").remove();

Hugs.

    
29.11.2017 / 14:00
1

You need to first get div and then get the child targets, something like this:

$("#lista").find("p").remove();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="lista">
   <p>Antonio Carlos Almeida Filhos</p>       
</div>

<div id="lista2">
   <p>Temer da Silva</p>         
</div>
    
29.11.2017 / 14:01