Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different methods to make a null link?

Tags:

Is there a way to make a null link besides these methods?

<a href="javascript:;">Example</a>  <a href="javascript:void(0);">Example</a>  <a href="#">Example</a> 

I don't mind something that makes the page jump to the top but I don't want it to alter the URL in the address bar. The ideal link would be one as similar as possible to the ones featured on navigation boxes on Wikipedia but there is much more to that link than meets the eye as it has a pretty large script associated with it. I'm just looking for something to put into the a tag.

Thanks in advance.

like image 330
ZeroGravity Avatar asked Sep 21 '11 05:09

ZeroGravity


People also ask

How do I create a blank link?

a target=”_blank” Open in New Browser Tab (or Window) The target attribute specifies where the linked document will open when the link is clicked. The default is the current window. If target="_blank" , the linked document will open in a new tab or (on older browsers) a new window.

What is null link?

If the parser is unable to find a complete linkage for a sentence - one which links all the words together according to the requirements of the words - it begins to use "null-links". It begins by trying to parse the sentence, ignoring one word.

How do I create a blank link in HTML?

a javascript:void(0) works nicely. If it doesn't link anywhere it's not really a link... For that reason I prefer cursor: pointer; over javascript:void(0) and also because if JavaScript is disabled, the link will break.

How do you make a href do nothing?

To make an anchor tag refer to nothing, use “javascript: void(0)”.


1 Answers

You just want something you can shove in the <a> tag? OK:

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

Combine it with any of the href= methods from your question.

Given that a link that doesn't go anywhere is fairly useless, can I assume you want to kick off some JavaScript function when the link is clicked? If so, do this:

<a href="#" onclick="yourFunctionHere(); return false;">Example</a> 
like image 125
nnnnnn Avatar answered Sep 28 '22 06:09

nnnnnn