"Turn" href= "#" with "javascript:void (0);" The difference

Source: Internet
Author: User

In the work, if we want to put the link in the a tag into an empty link, we generally use two methods:
1 <a href="#"target="_blank"></a>
Or
1 <a href="javascript:void(0);"target="_blank"></a>
The above two methods many people think is the method of empty link, but the two methods are different, what is the difference? Let's talk about it today. Href= "#" method: In fact, is also the meaning of empty connection, but after the click will automatically jump to the top of the page, because this method is equivalent to click on an anchor, but this anchor is not written ID, so the default jump to the top of the page. href= "javascript:void (0);" Method: Void is an operator that specifies to evaluate an expression but does not return a value. If you write 0 (void (0)) in void, nothing is done and an empty link is formed. #与javascript: void (0) differs: So, #与javascript: the difference between void (0) is also obvious, #方法会跳转到页面的顶部, and a # appears after the page URL, and the Javascript:void (0) method does not, So if it is an empty connection, it is recommended to Javascript:void (0).

The difference between href= "#" and href= "javascript:void (0)"

"#" contains a location. The default anchor point is #top, which is the top of the page, and Javascript:void (0) represents only a dead link. This is why sometimes the page is very long browse the link is obviously # but the jump to the first page and javascript:void (0) This is not the case, so it's best to use void (0) when invoking a script.

"Go" href= "#" and "javascript:void (0);" The difference

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.