$('a').click(function() {
var title = $(this).attr('title');
alert(title);
});
You can simply use this.title
inside the function
$('a').click(function() {
var myTitle = $(this).attr ( "title" ); // from jQuery object
//var myTitle = this.title; //javascript object
alert(myTitle);
});
Note
Use another variable name instead of 'alert'. Alert is a javascript function and don't use it as a variable name
$('a').click(function() {
var title = $(this).attr('title');
alert(title);
});
Even you can try this, if you want to capture every click on the document and get attribute value:
$(document).click(function(event){
var value = $(event.target).attr('id');
alert(value);
});
$(this).attr("title")
You can create function and pass this function from onclick event
<a onclick="getTitle(this);" title="Some stuff here">Link Text</a>
<script type="text/javascript">
function getTitle(el)
{
title = $(el).attr('title');
alert(title);
}
</script>