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.