// Check that the attribute exists before you set a value
const d = document.getElementById("div1");
if (
d.hasAttributeNS("http://www.mozilla.org/ns/specialspace/", "special-align")
) {
d.setAttribute("align", "center");
}Element: hasAttributeNS() method / notebook
Element: hasAttributeNS() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.