Pergunta

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

...

Foi útil?

Solução

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");
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top