Sunday, January 8, 2017

Get anchor text/href upon onclick using jQuery



Note: Apply the class info_link to any link you want to get the info from.
<a class="info_link" href="~/Resumes/Resumes1271354404687.docx">
    ~/Resumes/Resumes1271354404687.docx
</a>
For href:
$(function(){
  $('.info_link').click(function(){
    alert($(this).attr('href'));
    // or alert($(this).hash();
  });
});
For Text:
$(function(){
  $('.info_link').click(function(){
    alert($(this).text());
  });
});

No comments:

Post a Comment