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! While you're at it, check out some resources Treehouse students have shared here.

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

JavaScript jQuery Basics Working with jQuery Collections Looping through a jQuery collection

Tibor Ruzinyi
Tibor Ruzinyi
17,968 Points

template literal

Can we use template literal to rewrite that code to this somehow?Its not working for me so how would be the syntax with the atrr if even possible? :

  const  $url = `${link}.${attr('href')}`;

1 Answer

Steven Parker
Steven Parker
229,644 Points

There really isn't an opportunity to use interpolation here, the only string on this line is the literal 'href'. No variables or expressions are being converted into string form.

I suppose you could put the entire thing in a template string; but that seems kind of silly, since the expression yields a string value already:

const $url = `${$(link).attr('href')}`;  // silly use of template string

Also "$url" is a questionable name for this variable, since it contains a string and not a jQuery object.