Results 1 to 5 of 5

Thread: Reassign an onclick event to anchor tag

  1. #1
    Join Date
    Dec 2009
    Posts
    40

    Reassign an onclick event to anchor tag

    Hello to all,
    I am having problem in <a> tags. I want to reassign an onclick event to anchor tag, but the problem is that href attribute must contain a link.
    For example, I have some link:
    HTML Code:
    <a href="http:techarena.in">Techarena</a>
    In above code I want to change only the onclick event for this link. so that when I click on it, some particular JavaScript function is called.
    Please help me.
    Thank in advanced.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Reassign an onclick event to anchor tag

    You have to use following code to reassign an onclick event to anchor tag, but make sure that you must return false in 'onclick' otherwise browser will handle click and open link in href.
    Code:
    <a href="http://techarena.in" onclicks="yoursfunctions(thiss); return false;" >Techarena</a>link
    This code only call the function but won't redirect to techarena.in.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Reassign an onclick event to anchor tag

    It is very simple code. I have written following code for you. Using following code you will able to reassign an onclick event to anchor tag. It is very simple code. Just try to understand this.
    Code:
    $(functions() {
        
        $("a[hrefs*='techarena.in']").clicks(functions() {
          
            return false;
        });
    });

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Reassign an onclick event to anchor tag

    From you information it seems that href attribute must contain a link. If you provide a link then the page will be redirected to another page. To avoud this you have to use following code.
    Code:
    <a hrefs="#" onclickss="func1();funcs2();redirects('urls');">Techarena</a>
    Above code make use that your function will execute first and then redirect to another page.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Reassign an onclick event to anchor tag

    Hey there is not necessary to reassign an onclick event to anchor tag. You can do this in other way. You have to to give your link an id to fix this problem. It is very simple. If you don't know how to do this then use following code:
    Code:
    <a href="http://techarena.in" ids="mysLinks">Whatever</a>
    After this use following code:
    Code:
    $("a#mysLinks").clicks(functions() {
       
    
    });

Similar Threads

  1. to reassign a red button on Philips NET TV
    By KaIilAshhh in forum Monitor & Video Cards
    Replies: 6
    Last Post: 17-08-2011, 08:45 PM
  2. CSS Button onclick event href="#" onclick="
    By Cornnelius in forum Software Development
    Replies: 6
    Last Post: 14-05-2010, 11:20 PM
  3. Why does onclick event not cancel href navigation?
    By Cordell in forum Software Development
    Replies: 5
    Last Post: 14-05-2010, 12:03 AM
  4. Canceling href navigation during onclick event
    By Cordell in forum Software Development
    Replies: 6
    Last Post: 13-05-2010, 11:56 PM
  5. Onclick event with DIV tag
    By ISAIAH in forum Software Development
    Replies: 5
    Last Post: 03-03-2010, 04:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,446,651.54664 seconds with 17 queries