1

I use this function to stip tags in javascript

noTags = result.strInputCode.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

...

2
  • cant you use the document.getElementsByClassName function?
    – Baz1nga
    Sep 1, 2011 at 11:45
  • Or use Jquery if you can. It is very easy to loop through all elements with a certain class. $('.className').each(function(){//remove tags})
    – mahulst
    Sep 1, 2011 at 11:53

1 Answer 1

0

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");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.