Reputation: 45
enter code here
i use: jquery-1.6.2.min.js
i want to get the content of an a tag -->> title <<-- attribute
example html code:
<div id='menu1' class="menu">
<a class="dock" href='#' title='some text bla bla 001'><img src='http://www.linktoimage.com/sample.jpg' /></a>
</div>
inside document ready function i use this jquery code:
$(function(){
$('.menu a').click(function(){
alert($(this).attr('title'));
// $('.headline').empty();
// $('.headline').append('<p>'+ $(this).attr('title') +'</p>');
});
});
problem:
alert only returns undefined
can someone help? thnx
Upvotes: 0
Views: 17028
Reputation: 12025
try
alert($(this).attr('title'));
return false;
after you click on the link the browser reloads, you need to return false to prevent it
Upvotes: 0
Reputation: 19550
.attr()
is proper for a title attribute, and your example code works fine: http://jsfiddle.net/z2zFe/
Upvotes: 0