Javascript: void (0) Example

Source: Internet
Author: User

When you do a page, if you want to do nothing after clicking a link, or respond to the click to complete other tasks, you can set its property href = "#", however, this may cause a problem: when the page has a scroll bar, clicking it will return to the top of the page, or jump to the place where the configured anchor is located. The user experience is poor.

The common usage is:
Copy codeThe Code is as follows:
<A href = "javascript: void (0)"> Click here to see the effect. </a>

In fact, clicking here will not happen. The javascript: void (0); format is a javascript pseudo protocol, which means that this link does not jump to any place.

Javascript: void (0) is used in the following forms:
Copy codeThe Code is as follows:
// Do not do anything after you click the link
<A href = "javascript: void (0);"> test </a>
<A href = "javascript:;"> test </a>
<A href = "####"> test </a> // use 2 to 4 #. For details, see "####", you can also use "# all" and other

Copy codeThe Code is as follows:
// Click the link to respond to user-defined click events
<A href = "javascript: void (0)" onclick = "doSomething ()"> test </a>

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.