0

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>
2
  • Please see How to Ask. What have you tried? Does this answer your question? How can I remove an attribute with jQuery? Commented Mar 21, 2022 at 18:17
  • Your HTML has extra characters. Is that what it actually looks like? Commented Mar 21, 2022 at 18:17

2 Answers 2

1

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')
})
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.