开发者

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 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜