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

Link building with

javascript:void(0) 

violate the W3C standard.

I need to have

  <a href=""> 

in my code, which is not clickable and conveys W3C standards. Please do not tell me to simply delete the link, because I need it for my menu, and the class is important.

How can I make a link that is worthless and is it W3C friendly?

+4
source share
3 answers

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

 <a href="#" onclick="return false;">Something</a> 
+13
source

There is no scroll on your page yet, why not

 <a href="#" id="yourDeadA"> document.getElementById("yourDeadA").addEventListener("click", function() { //run your code return false; }); 
+4
source

This should work fine:

 <a href="#"></a> 
0
source

Source: https://habr.com/ru/post/1387408/


All Articles