What is href=“#” and why is it used?

前端 未结 9 708
离开以前
离开以前 2020-11-22 12:49

On many websites I see links that have href=\"#\". What does it mean? What is it used for?

9条回答
  •  旧时难觅i
    2020-11-22 13:26

    The href attribute defines the URL of the resource of a link. If the anchor tag does not have href tag then it will not become hyperlink. The href attribute have the following values:

    1. Absolute path: move to another site like href="http://www.google.com"
    2. Relative path: move to another page within the site like herf ="defaultpage.aspx"
    3. Move to an element with a specified id within the page like href="#bottom"
    4. href="javascript:void(0)", it does not move anywhere.
    5. href="#" , it does not move anywhere but scroll on the top of the current page.
    6. href= "" , it will load the current page but some browsers causes forbidden errors.
    
    Note: When we do not need to specified any url inside a anchor tag then use 
    Test1
    

提交回复
热议问题