Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a HTML link that does nothing (literally nothing)

Tags:

html

css

I want a link that does nothing. I don't want this:

<a href="#">

because then the URL becomes something.com/whatever/#.

The only reason I want a link is so the user can see that they can click on the text. JavaScript is being used to perform some action so I don't need the link to go anywhere but I need it to look like a link!

I could use some data attribute and tell me CSS to make elements look like links if they have this attribute but it seems a bit overkill.

like image 446
ale Avatar asked Nov 24 '11 17:11

ale


People also ask

How do you make a link do nothing in HTML?

To make an anchor tag refer to nothing, use “javascript: void(0)”. The following link does nothing because the expression "0" has no effect in JavaScript. Here the expression "0" is evaluated, but it is not loaded back into the current document.

How do I make an href empty?

The Short Answer: href="#0" I like this because: It doesn't navigate. It makes it obvious that this it's a do-nothing navigation.

How do you make a simple link in HTML?

To make a hyperlink in an HTML page, use the <a> and </a> tags, which are the tags used to define the links. The <a> tag indicates where the hyperlink starts and the </a> tag indicates where it ends. Whatever text gets added inside these tags, will work as a hyperlink. Add the URL for the link in the <a href=” ”>.


2 Answers

The following will prevent your href from being ran

<a href="#" onclick="return false;"> 

If you are using jQuery, event.preventDefault() can be used

like image 194
Curtis Avatar answered Oct 13 '22 23:10

Curtis


Try this:

<a href="javascript:void(0);">link</a> 
like image 35
alexdets Avatar answered Oct 14 '22 01:10

alexdets