开发者

Javascript: Strip tags with desired class

开发者 https://www.devze.com 2023-04-01 15:37 出处:网络
I use this function to stip tags in javascript noTags = result.strInputC开发者_如何学JAVAode.replace(/<\\/?[^>]+(>|$)/g, \"\");

I use this function to stip tags in javascript

noTags = result.strInputC开发者_如何学JAVAode.replace(/<\/?[^>]+(>|$)/g, "");

but how can i only remove tags if the hay a desired class??

for example, from

Remove only tags with classes: 'tooltip_left', 'tooltip_right', 'tooltip_bottom' and keep

...


What about this: (js fiddle demo)

var StripTags = function (desiredClass)
{
    var nodes = document.querySelectorAll('.' + desiredClass);
    for (var i = 0; i < nodes.length; i++)
        nodes[i].parentNode.removeChild(nodes[i]);
}

StripTags("tooltip_left");
StripTags("tooltip_right");
StripTags("tooltip_bottom");
0

精彩评论

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