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");
精彩评论