Jump to content
Sign in to follow this  
davej

javascript:void(0);

Recommended Posts

What is the significance of javascript:void(0); ??? Often I click on a link and nothing happens and I see javascript:void(0); Perhaps my host file or popup blocker has blocked it?

Share this post


Link to post
Share on other sites

Very old-fashioned code sometimes assigned the href attribute the value javascript:void(0) . This is basically a javascript statement that does nothing, so it keeps the link from behaving like a link without really doing anything else. You might also see some sort of "onclick" attribute in the tag also. None of this is good style in HTML5 (or HTML 4, for that matter). It's better to assign event handlers in the main script. It's also better to use some other element besides a link to trigger behavior that is not link-like. (It is appropriate for a link to trigger behavior before it changes the location, but not instead of that)

Edited by Deirdre's Dad

Share this post


Link to post
Share on other sites

 javascript:void(0) is not a very critical error, it sure is an irritating to encounter. When you encounter the javascript:void(0) error it most probably is an indication of an error stemming from your browser; which in turn blocks you from accessing a particular website. The root cause of the error can be traced to a resident pop up blocker in your internet browser. Also, it may be triggered by a proxy server if you are connecting to the internet through proxy.

The void operator evaluates the given expression and then returns undefined. If you have pass 0 as the unary expression operand to the void operator, JavaScript coerces 0 to "false" and returns, but void doesn't care and simply returns undefined, which means "do nothing" . Put them together and you have composed a way to programmatically "do nothing" when a link is clicked. JavaScript Void(0) is often used when, inserting an expression into a web page may produce an unwanted side-effect.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...