Quantcast
Channel: Which "href" value should I use for JavaScript links, "#" or "javascript:void(0)"? - Stack Overflow
Browsing all 57 articles
Browse latest View live

Answer by Nedim AKAR for Which "href" value should I use for JavaScript...

javascript:void(0) will deprecate in future, therefore you should use #.

View Article



Answer by Stokely for Which "href" value should I use for JavaScript links,...

There are actually four options here.Using return false; allows you to keep the anchor version in cases where you want a safe "fallback" in browsers that have JavaScript disabled or it is not supported...

View Article

Answer by Dev pokhariya for Which "href" value should I use for JavaScript...

The most simple and used by everyone mostly is javascript:void(0) You can use it instead of using # to stop tag redirect to header section.<a href="javascript:void(0)"...

View Article

Answer by Javed Khan for Which "href" value should I use for JavaScript...

You can use javascript:void(0) here instead of using # to stop anchor tag redirect to header section.function helloFunction() { alert("hello world");}<a href="javascript:void(0)"...

View Article

Answer by SchoolforDesign for Which "href" value should I use for JavaScript...

•Javascript: void(0); is void to null value [Not assigned], which that mean your browser is going to NULL click to DOM, and window return to false.• The '#' is not follow the DOM or Window in...

View Article


Answer by L Y E S - C H I O U K H for Which "href" value should I use for...

Edited on 2019 JanuaryIn HTML5, using an a element without an href attribute is valid. It is considered to be a "placeholder hyperlink"If the a element has no href attribute, then the element...

View Article

Answer by Charlie for Which "href" value should I use for JavaScript links,...

Bootstrap modals from before 4.0 have a basically undocumented behavior that they will load hrefs from a elements using AJAX unless they are exactly #. If you are using Bootstrap 3, javascript:void(0);...

View Article

Answer by TomDK for Which "href" value should I use for JavaScript links, "#"...

On a modern website the use of href should be avoided if the element is only doing JavaScript functionality (not a real link).Why?The presence of this element tells the browser that this is a link with...

View Article


Answer by user6460587 for Which "href" value should I use for JavaScript...

I tried both in google chrome with the developer tools, and the id="#" took 0.32 seconds. While the javascript:void(0) method took only 0.18 seconds. So in google chrome, javascript:void(0) works...

View Article


Answer by Garrett for Which "href" value should I use for JavaScript links,...

Don't use links for the sole purpose of running JavaScript.The use of href="#" scrolls the page to the top; the use of void(0) creates navigational problems within the browser.Instead, use an element...

View Article

Answer by dnetix for Which "href" value should I use for JavaScript links,...

I usually go for<a href="javascript:;" onclick="yourFunction()">Link description</a>It's shorter than javascript:void(0) and does the same.

View Article

Answer by AlxGol for Which "href" value should I use for JavaScript links,...

Why not using this? This doesn't scroll page up.<span role="button" onclick="myJsFunc();">Run JavaScript Code</span>

View Article

Answer by mdesdev for Which "href" value should I use for JavaScript links,...

I personally use them in combination. For example:HTML<a href="#">Link</a>with little bit of jQuery$('a[href="#"]').attr('href','javascript:void(0);');or$('a[href="#"]').click(function(e) {...

View Article


Answer by Anders M. for Which "href" value should I use for JavaScript links,...

I'd say the best way is to make an href anchor to an ID you'd never use, like #Do1Not2Use3This4Id5 or a similar ID, that you are 100% sure no one will use and won't offend people.Javascript:void(0) is...

View Article

Answer by Vinny Fonseca for Which "href" value should I use for JavaScript...

I use href="#" for links that I want a dummy behaviour for. Then I use this code:$(document).ready(function() { $("a[href='#']").click(function(event) { event.preventDefault(); });});Meaning if the...

View Article


Answer by Ashish Kumar for Which "href" value should I use for JavaScript...

So, when you are doing some JavaScript things with an <a /> tag and if you put href="#" as well, you can add return false at the end of the event (in case of inline event binding) like:<a...

View Article

Answer by whirlwin for Which "href" value should I use for JavaScript links,...

If you happen to be using AngularJS, you can use the following:<a href="">Do some fancy JavaScript</a>Which will not do anything.In additionIt will not take you to the top of the page, as...

View Article


Answer by G. Ghez for Which "href" value should I use for JavaScript links,...

You should not use inline onclick="something();" in your HTML to not polluate it with meaningless code; all click bindings must be set in Javascript files (*.js).Set binding like this :...

View Article

Answer by vol7ron for Which "href" value should I use for JavaScript links,...

You could use the href and remove all links that have only hashes:HTML:<a href="#" onclick="run_foo()"> foo </a>JS:$(document).ready(function(){ // on DOM ready or some other event...

View Article

Answer by Stacks on Stacks on Stacks for Which "href" value should I use for...

When I've got several faux-links, I prefer to give them a class of 'no-link'.Then in jQuery, I add the following code:$(function(){ $('.no-link').click(function(e){ e.preventDefault(); });});And for...

View Article
Browsing all 57 articles
Browse latest View live




Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>