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

Tibor Ruzinyi
Tibor Ruzinyi
13,877 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
173,537 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.