开发者

jquery removing element

开发者 https://www.devze.com 2023-03-28 01:57 出处:网络
I have to remove certain elements without removing the entire div.For example Here, <div> <p>Hello</p>

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

<div>
    <p>Hello</p>
    <h1>Stack Overflow</h1>
    <div>This i开发者_开发技巧s 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.


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/

0

精彩评论

暂无评论...
验证码 换一张
取 消