Remove all attributes

后端 未结 9 617
天涯浪人
天涯浪人 2020-11-27 04:01

Is it possible to remove all attributes at once using jQuery?


to



        
相关标签:
9条回答
  • 2020-11-27 04:53

    A simple method that doesn't require JQuery:

    while(elem.attributes.length > 0)
        elem.removeAttribute(elem.attributes[0].name);
    
    0 讨论(0)
  • 2020-11-27 04:53

    One-liner, no jQuery needed:

    [...elem.attributes].forEach(attr => elem.removeAttribute(attr.name));
    
    0 讨论(0)
  • 2020-11-27 04:55

    One-liner.

    For jQuery users

    $('img').removeAttr(Object.values($('img').get(0).attributes).map(attr => attr.name).join(' '));
    
    0 讨论(0)
提交回复
热议问题