3

I want to create a link that does NOTHING, it means that its a fake link

Im trying with onclick="mijava();return false;" but it scrolls up in the website

How can I do it?

1
  • 1
    Why do you want to create a link that does nothing? This sounds like an XY problem: you have one problem, and you think that creating an a element that does nothing will solve it. So... what is the issue you're trying to solve?
    – Mr Lister
    Oct 22, 2015 at 16:41

5 Answers 5

3

javascript:

document.getElementById("nothing").addEventListener("click", function(event){
event.preventDefault()
});

html:

<a id="nothing" href="#">Link</a>

JSFiddle

3

"javascript:void(0)" to href attribute, the <a> tag will do nothing.

2

This won't do anything.

<a href="">Link</a>
2
  • I believe it was not valid to write it like this, i just checked it and it is Valid! +1 Oct 22, 2015 at 16:33
  • But it will still scroll up to the top of the page, unless you preventDefault() it Oct 22, 2015 at 16:51
0

Do you test it that?

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

You can use CSS to style it like a link and you probably don't want to use an anchor tag if it's not going to act like one.

See this answer: How to make an anchor tag refer to nothing?

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.