Usage of href = & quot; # & quot; and javascript: void (0)

Source: Internet
Author: User

Generally, we set the href attribute of the tag that is not oriented #

1 <a href = "#"> Delete </a>

For example, when we do not need to add or delete a new link, we do not need to do any guidance, but click this link to execute a string of javascript code.
However, when the position of tag a exceeds the page scroll bar, the link we click does not have any orientation, but the page returns to the top.
This is very bad. It can be said that the user experience is quite poor.
The reason is # It can be regarded as an anchor link. When we click

1 <a href = "#"> Delete </a>

The page is directed to the top

So how can we solve this problem?
We can change the code to this

1 <a href = "javascript: void (0)"> Delete </a>

Or

1 <a href = "javascript: return false"> Delete </a>

Even if the page exceeds the scroll bar, when we click the link, the page will not return to the top.

Related Article

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.