Home > Enterprise >  How can I remove On click attribute using "nav-item dropdown" class
How can I remove On click attribute using "nav-item dropdown" class

Time:03-22

How can I remove On click attribute using "nav-item dropdown" class

<li >                    
<a  "="" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" onclick="window.location.href='/camping-tents'">Camping Tents</a></li>

<li >                    
<a  "="" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" onclick="window.location.href='/camping-tents2'">Camping 3</a></li>

<li >                    
<a  "="" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" onclick="window.location.href='/camping-tents3'">Camping 3</a></li>

<li ><a  bell-tents" style="background:0;"> Bell Tents</a></li>

CodePudding user response:

First, fix your markup issues. Then, use .removeAttribute('onclick') method on the elements in question.

CodePudding user response:

You can use querySelectorAll to get all links under elements that have "nav-item dropdown" class and then itirate over these a elements to remove their onclick attributes:

Array.from(document.querySelectorAll('.nav-item.dropdown a')).forEach((el) => {
  el.removeAttribute('onclick')
})
  • Related