Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery removing element

I have to remove certain elements without removing the entire div.For example Here,

<div>
    <p>Hello</p>
    <h1>Stack Overflow</h1>
    <div>This is a wonderful site</div>
</div>

I have to remove <p> and <div> tags without emptying whole div.Is there any usage of child selectors for removing like this in jquery.

like image 786
Bhaskar Avatar asked Nov 23 '25 05:11

Bhaskar


1 Answers

try this $("div").children("p,div").remove();

Using children() you can select the element you wish to remove.

Demo: http://jsfiddle.net/tT97f/

Another method is using child selector > for example $("div > p, div > div").remove();

Demo: http://jsfiddle.net/tT97f/1/

like image 132
Sotiris Avatar answered Nov 25 '25 00:11

Sotiris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!