var data = '<p><span class="unwanted-span-one" data-hello="unwated-attr">Donec</span> rutrum congue leo eget malesuada. <span>Mauris</span> blandit aliquet elit, eget <span class="unwanted-span-two" data-hello="unwated-attr-two"> malesuada</span>.</p>'
I want to remove all span tag which has a class name start with "unwanted-span-", it should remove only the tag wrap not inside content.
so the desired output should be as follow
var data = <p>Donec rutrum congue leo eget malesuada. <span>Mauris</span> blandit aliquet elit, eget malesuada.</p>'
Let me know if it's possible or not. If yes can you please help me with that.
Please note -- we only need to remove span tags with class name starts "unwanted-span-" other span should remain as it is.
Alessio Chiffi
Frontend Web Developer
const span = [...document.querySelectorAll('span')]; span.forEach(function (span) { if (span.className.indexOf('unwanted-span') !== -1) { span.parentNode.removeChild(span); } });I have just seen that you want to remove just the data-tag, there are many ways to do that. The above is a function that will let you do anything with the 'unwanted' spans.