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.


Promoted By Zergnet


You May Also Like

  • What is JavaScript Void?

    Tizag: JavaScript Void 0 Tutorial; Cubiczone: The Infamous JavaScript Void() Function; Resources. TopBits: JavaScript Void(0) Errors; D'bug: Avoid the Void;

  • How to Use the Void Function

    Tizag; Javascript Tutorial - Void 0; Quackit; JavaScript Void(0) University of Virginia; Computer Science Department; Valued Functions and Void Functions;

  • How to Use OnClick in JavaScript

    Note the use of single quotes for strings within the JavaScript code to avoid conflicting with the double quotes used for the...

Related Searches

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