javascript - referencing jquery global variables inside html? -


i new jquery.

i have below line of code: need refer variable inside html () function.

$('#myform #formprogress').html('<img src="ajax-loader.gif" /> saving&hellip;'); 

now img src have in variable below.

var url = document.location.host; var url2 = url.concat("/myapp/public/images/ajax-loader.gif"); 

now inside need pass url2 img src tag. how can that?

thanks!

two ways:

$(...).html('<img src="' + url2 + '"/>saving...') 

or:

$(...).append($('<img/>').attr('src', url2)) 

the second method cleaner/better imho.


Comments