KBlack
KBlack

Reputation: 45

jquery attr('title') a tag

enter code herei 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

Answers (3)

Alon Eitan
Alon Eitan

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

JAAulde
JAAulde

Reputation: 19550

.attr() is proper for a title attribute, and your example code works fine: http://jsfiddle.net/z2zFe/

Upvotes: 0

Moin Zaman
Moin Zaman

Reputation: 25435

It works. See my fiddle here: http://jsfiddle.net/STN9j/

Upvotes: 2

Related Questions