When converting a div
into a string using
, I want to be able to select specific DOM attributes for serialization.new XMLSerializer().serializeToString()
For instance:
let element1 = document.getElementById('element1');
element1.style.color = "blue";
console.log(new XMLSerializer().serializeToString(element1));
#element1 { font-size: 16px; }
<div id="element1">Hello</div>
Instead of ...
<div xmlns="http://www.w3.org/1999/xhtml" id="element1" style="color: blue;">Hello</div>
...I would like to serialize all attributes except the color
style attribute:
<div xmlns="http://www.w3.org/1999/xhtml" id="element1">Hello</div>
Is there a way to specify which attributes to include in the serialization when using
?new XMLSerializer().serializeToString()