How to find link title text

How to find link title text in jQuery.

+4
source share
5 answers

You can use attr to search for the title attribute.

 var title = jQuery("a").attr("title"); //replace "a" with your own selector 
+5
source

I think you mean the link text:

 var link_text = $('#someLink').text(); 

If you mean the title attribute (the text that you see when you hover over the link):

 var link_title = $('#someLink').attr('title'); 
+4
source
 $("a").click(function(e){ e.preventDefault(); var title = $(this).attr("title"); }); 
+2
source

You get attributes such as a title for links (or any other element):

 $('a').attr('title'); 
+2
source

If you are trying to get the text of the title attribute of a link, you can use this considering that myLink is the jQuery object of your link:

 myLink.attr("title") 

However, if you mean the actual text of the link, you can use this:

 myLink.text() 

You can read the jQuery documentation for the attr method here and the documentation for the text method here .

+1
source

All Articles