-1

I have a class of span elements in which tinymce-generated texts are embedded.

<span class="ArticleSummary">
This text is generated with a text editor and may have a lot of inline stylings.
</span>

This text is normally full of elements with inline styling. How can I disable all the inline stylings of that text and get pure html of it to be able to style the whole span outside with other css code?

Stack crawler
  • 369
  • 1
  • 4
  • 20

1 Answers1

3

Loop over all the elements and delete all the style attributes.

var mySpan = document.querySelector('span');

var elements = mySpan.querySelectorAll("*");
for (var i = 0; i < elements.length; i++) {
  elements[i].removeAttribute("style");
}
<span>
  <a href="http://example.com/" style="color: red;">Hello <strong>World</strong></a> — <cite style="text-decoration: overline;">Brian Kernighan</cite>
  </span>
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335