Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


how to change data-icon value dynamically ?

I have this code of line in my HTML and i want to change it's attr value how i can insert value to do same...

<a href="#" data-icon="&#xea3c;"></a>
 $(this).attr("data-icon",&#xea3c; ); //here i want to insert value dynamically

1 Answer

Matt F.
Matt F.
9,518 Points

$('a').attr("data-icon", '' );


$('a').data("icon", '' );

I am not sure what you are looking to use this for, but you needed to target the anchor element (replace 'this' with 'a'), as well as wrap the second argument to attr/data a string.