Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: How to get the value of an html attribute?

Tags:

jquery

I've got an html anchor element:

<a title="Some stuff here">Link Text</a>

...and I want to get the contents of the title so I can use it for something else:

$('a').click(function() {
    var title = $(this).getTheTitleAttribute();
    alert(title);
});

How can I do this?

like image 434
Andrew Avatar asked Dec 04 '09 05:12

Andrew


3 Answers

$('a').click(function() {
    var title = $(this).attr('title');
    alert(title);
});
like image 85
yoda Avatar answered Oct 03 '22 02:10

yoda


$('a').click(function() {
    var title = $(this).attr('title');
    alert(title);
});
like image 44
awgy Avatar answered Oct 03 '22 01:10

awgy


$(this).attr("title")
like image 28
Josh Gibson Avatar answered Oct 03 '22 01:10

Josh Gibson