Remove Attribute with JavaScript

Posted on: June 22nd, 2022
By: Tadeo Martinez

https://developer.mozilla.org/en-US/docs/Web/API/Element/removeAttribute

removeAttribute(attrName)

document.getElementById("div1").removeAttribute("align");

Here’s how I used it personally on a website:

let subMenuLinks = document.querySelectorAll('.sub-menu li a');

for (i = 0; i < subMenuLinks.length; i++) {
    console.log(subMenuLinks[i]);
    subMenuLinks[i].removeAttribute('href');
}

Have any questions or comments? Write them below!


Leave a Reply

Your email address will not be published. Required fields are marked *