I have large block of html that is stored in a variable that contains a variable that should increment upon function.
Seems like this is very basic, yet couldn't figure out.
var x = 1,
foo = '<p>This should count ' + x +'</p>';
$('#add').click(function () {
$('#form-dynamic').append(form);
x++;
});
fooinside theclickhandler.xinstead ofcountandforminstead offoo? Otherwise I can't make any connection.foois a string. Even though you originally built it using the value ofx, the string won't magically update ifxchanges. Think about this simplified example:var a = 1; var b = 2 + x;. At this point,bhas the value3. Would you expect that if I doa = 3,bwill also somehow update to5? Instead, wheneverxchanges have to "rebuild"foo.