user6193206
user6193206

Reputation:

remove Attribute "contenteditable" from entire document

I have the problem that some <span> elements have the Attribute "contenteditable=true".

That is a problem it should be false.

I am using this as temporary fix

for (i = 0; i < document.getElementsByTagName("span").length; i++) {
    document.getElementsByTagName("span")[i].removeAttribute("contenteditable");
}

But this is not that fast. Is there a better way to remove all "contenteditable" Attributes from the html?

Upvotes: 2

Views: 1946

Answers (1)

Satpal
Satpal

Reputation: 133403

You can use document.querySelectorAll() to refer span which have contenteditable attribute.

document.querySelectorAll("span[contenteditable]").forEach(function(el){
  el.removeAttribute("contenteditable");
})

Upvotes: 4

Related Questions