Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript:void(0) not accepted by W3C, how to resolve this?

Making a link with

javascript:void(0)

violate the W3C standard.

I need to have a

 <a href="">

in my code that is not clickable and pass the W3C norms. Please don't tell me to just remove the a link because I need it for my menu and the class is important.

How could I make a link that goes nowhere and it's W3C friendly ?

like image 409
Warface Avatar asked Dec 03 '22 05:12

Warface


2 Answers

Just use this onclick event, which does exactly the same as void(0)

<a href="#" onclick="return false;">Something</a>
like image 83
Martin. Avatar answered Dec 25 '22 12:12

Martin.


So long as there's not any scrolling on your page, why not

<a href="#" id="yourDeadA">

document.getElementById("yourDeadA").addEventListener("click", function() {
    //run your code
    return false;
});
like image 25
Adam Rackis Avatar answered Dec 25 '22 10:12

Adam Rackis