I want to set title text of a link calling a function which receives as parameter the id of the element and outputs the text.
something like
$(a).attr('title', function() {return $(this).id + "foo"});
but a construct like this doesn't exist as far I know. What can I do? Thanks.
Use $(this).attr('id')
or this.id
. Do not mix them.
$(a).attr('title', function() {return $(this).attr('id') + "foo"});
$(a).attr('title', function() {return this.id + "foo"}); // <-- Preferred
//^ Is this a a variable? If not, you have to quote it: $("a").attr( ... );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With