Href = & quot; javascript: void (0); & quot; Difference,

Source: Internet
Author: User

Href = "javascript: void (0);" and,

There are two ways to set the <a> label to null link. The first is href = "#", and the other is href = "javascript: void (0 );". Both methods set the label to null link, but the two methods are somewhat different.

Href = "#". When you click it, it will jump to the top of the page, which is equivalent to clicking an anchor. A # identifier will appear after the URL.

While href = "javascript: void (0);" is to execute a javascript expression. Void (0) does not execute or return anything, so no jump occurs.

We recommend that you use href = "javascript: void (0 );"


A href = "javascript: void (0)" What is it? What is the difference between adding or not?

<A href = "javascript: void (0)"> click </a> the link does not return to the top of the page.
<A href = "#"> click </a>.

What is the void () function in href = "javascript: void (0 )"?

Void is an operator in JavaScript. Its usage format is as follows:
1. javascript: void (expression)
2. javascript: void expression

Expression is a standard Javascript expression to be calculated. Parentheses outside the expression are optional, but it is a good habit to write them. (Implement version Navigator 3.0)

In your example, use the void operator to specify a hyperlink. The expression will be calculated but will not load any content in the current document. That is to say, when the user does not do anything (jump ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.