I have this jQuery code
$("#selector").html('<a href=url>text</a>');
where url
and text
are JavaScript variables. How would I evaluate them inside quotes?
You just concatenate the strings together with +
:
$('#selector').html('<a href='+url+'>'+text+'</a>');
While @kingjiv's answer is absolutely right, if you'll be doing a lot of templating with jQuery it might be worth checking out the tmpl* plugin to help keep things organized.
*note: This plugin never made it past beta, and is no longer being maintained, the link above is for archival purposes only.
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