开发者

Javascript: Strip tags with desired class

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜