Issue
How can I remove On click attribute using "nav-item dropdown" class
<li class="nav-item dropdown">
<a class="nav-link " "="" 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 class="nav-item dropdown">
<a class="nav-link " "="" 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 class="nav-item dropdown">
<a class="nav-link " "="" 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 class="nav-item"><a class="nav-link " bell-tents" style="background:0;"> Bell Tents</a></li>
Solution
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')
})
Answered By - Tim
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.