This website may use cookies. More info. That's Fine x
Welcome Login

a tag (anchor tag)


Html

The anchor <a> tag is used to create hyperlinks and bookmarks.

Web page or site:

<a href="/folder/page">

 

Open to a new browser page:

<a href="/folder/page" target="_blank">

 

 

Local page:

<a href="pagename.html">

 

Local page in a folder level below:

<a href="foldername/pagename.html">

 

Local page in a folder level above:

<a href="../pagename.html">

 

 

Open email program with email address:

<a href="mailto:andrewsin@rocketmail.com">

 

 

Bookmarked section:

<a href="#bookmarkname">

 

Eg:

<!-- link to bookmark -->
<a href="#moreinfo">Click here for more info</a>

<!-- this is the bookmark -->
<a name="moreinfo">More Info</a>

 

Bookmarked section in another page:

<a href="pagelocation.htm#bookmarkname">

 

 

To stop an anchor link from a page reload in asp.net:

Try:

<a href="#" onclick="return false;">link</a>

 

 

 

Anchor tag href and onclick precedence:

If you have an anchor tag with an onclick event bound to it, then the click event is executed first, then the redirect (specified in href attribute of your anchor tag).

Eg: asp.net webform example:

When you click on the hyperlink, it's fg color will turn red before you are navigated away from the current page.

// aspx:
<style>
    .highlight {
        color: red !important;
    }
</style>

<script>
    $(document).ready(function() {
        $('.btn_home').click(function () {
            $(this).addClass('highlight');
        });
    });
</script>

<!-- this renders out as an anchor link -->
<asp:HyperLink CssClass="btn_home" ID="HyperLink1" runat="server" NavigateUrl="/Home.aspx#start" >Home</asp:HyperLink> 

 

 

For more information, see here.


Created on: Friday, September 30, 2011 by Andrew Sin