Which href to use for JavaScript links: "#" or "javascript:void(0)"?
Hi everyone! I'm a beginner frontend developer and I've run into a dilemma. When I create links that should execute JavaScript code instead of navigating to a URL, I don't know what to put in the `href` attribute.
Previously, I just used `href="#"`, but I noticed the page scrolls to the top, even though I return `false` from the handler. Recently, I saw code using `href="javascript:void(0)"`. But this seems strange to me — mixing JavaScript with HTML.
Here's an example of my current implementation:
```html
Click me
Click me
Click me
```
The problem
No answers yet.
Log in to leave an answer