Andrew Andrew - 5 months ago 9
jQuery Question

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

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?

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