Mitya Ustinov
Mitya Ustinov

Reputation: 903

Extract link's title value

How can I append link's title value as a link's text. I have this code:

<a href="#" title="Title value"></a>

...and after clicking on it I want to have something like this:

<a href="#" title="Title value">Title value</a>

Thank you!

Upvotes: 1

Views: 83

Answers (2)

akluth
akluth

Reputation: 8583

This

$('a').click(function() {
    $(this).text($(this).attr('title'));
}

should work.

Maybe you want to give your <a> tag a special ID, so you can reference it.

Upvotes: 0

Rory McCrossan
Rory McCrossan

Reputation: 337560

Try this:

$("a").click(function() {
    $(this).text($(this).prop("title"));
});

Upvotes: 4

Related Questions