0

which is better href="#" or href="javascript:void();" in terms of all aspects

like user experience, speed etc

is it necessary to put a 0 inside void when using href="javascript:void();" .like this href="javascript:void(0);"

Justin
  • 91
  • 1
  • 8

1 Answers1

1

If you don't need a link - don't use the <a> element. You can use any other element (div/span) and attach a click event to it:

EL.addEventListener('click', function() { ... })

The EL in the above example can by document.getElementById('#div-id') for example or any other DOM element.

Dekel
  • 60,707
  • 10
  • 101
  • 129