简体   繁体   中英

removeAttribute do not return true or false

I am trying to remove attributes of a DOM element using below statement in javascript.

var res = nodes.removeAttribute("style");

but the res is always "undefined" it seems that the removeAttribute function does not return anything (I tested it on firefox browser)

How can I identify that the attribute is successfully removed or not ?

Thanks, Sourabh

node ? It seems that you have an array of node s. Anyway, removeAttribute will not return anything. To check if the attribute has been removed, use hasAttribute afterwards.

node.removeAttribute('foo');
if (node.hasAttribute('foo')) {
  // failed, foo still exists.
}

nodes.removeAttribute("style");

var isTheLanguageWorkingLikeItShouldAndThisCheckIsTotallyPointless = nodes.getAttribute("style");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM