How to Avoid Javascript Void


The "javascript:void(0);" statement is often when a link has no URL attached to it but is used to reference a JavaScript function. If there is no URL attached to the link, the browser does not know what to do and returns you to the top of the page. Using "javascript:void(0)" in this instance can cause certain browsers to present your web page in unusual ways. Instead, you should use the "return false;" statement to tell the browser not to look for the URL.

Things You'll Need

  • Text editor
  • Open the document in any text editor.

  • Locate the "javascript:void(0)" references within the document.

  • Replace the links with the pound symbol (#) with the syntax "<a href="#"'>."

  • Add the "return false" declaration to the statement. The entire link reference would look like:

    <a href="a" onClick="callFunction();return false;">Link</a>

    Replace "callFunction()" with the name of your function.

  • Save and close the file.

Related Searches


Promoted By Zergnet


You May Also Like

  • What is JavaScript Void?

    JavaScript is a programming language used over the web. Modern web browsers like Internet Explorer, Safari and Firefox all allow you to...

  • How to Use OnClick in JavaScript

    The onClick event is triggered, or fired, whenever an HTML element on a page is clicked by the user. By defining an...

Related Searches

Check It Out

Geek Vs Geek: Robot battles, hoverboard drag race, and more

Is DIY in your DNA? Become part of our maker community.
Submit Your Work!