开发者

removing unwanted tags from html body with jQuery

开发者 https://www.devze.com 2023-01-07 01:56 出处:网络
I have 开发者_StackOverflowinherited some legacy HTML in which it has the following elements in the body of the code:

I have 开发者_StackOverflowinherited some legacy HTML in which it has the following elements in the body of the code:

style

meta

title

How do i remove these with jQuery?


If you can find a proper CSS selector to get to the elements you can simply detach them from the DOM:

$(document).ready(function(){
    $('style, meta, title').detach();
});

I highly doubt you really want to detach the <title> element, though.


$('style, meta, title').remove();

This would remove all of the specified elements from the DOM.

P.S. Make sure this is contained in the $(document).ready(), as is good practice for most jQuery code you will have to write.

0

精彩评论

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