开发者

how to find title text of a link

How开发者_StackOverflow社区 do I find the title text of a link in jquery.


You can use attr to find title attribute.

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


I think you mean the text of the link:

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');


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

$('a').attr('title');


$("a").click(function(e){
  e.preventDefault();
  var title = $(this).attr("title");
});


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

myLink.attr("title")

However, if you mean the actual text of the link, then 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜