Skip to content Skip to sidebar Skip to footer

How To Get The Href Of A Link Using Jquery?

I have a simple jquery code: $(function(){ $('#note_pag a').click(function(){ alert('click'); return false;

Solution 1:

Within the event handler, this is a reference to the element clicked. You can then use that DOM element to build a jQuery selection, and then use the attr function to get the value of the href attribute:

$(function(){                              
   $('#note_pag a').click(function(){      
    alert('cliccato link');  
    alert($(this).attr('href'));              
    returnfalse;                          
   });                                     
});            

Solution 2:

$(function(){                              
   $('#note_pag a').click(function(){      
    alert($(this).attr('href'));                
    returnfalse;                          
   });                                     
});

Check here http://jsfiddle.net/pHhw5/

Post a Comment for "How To Get The Href Of A Link Using Jquery?"