I want to create a jQuery statement that looks like this:
$('.total_999').html("something");
However, 999
comes from variable called storeNo
.
How can I construct this statement dynamically?
I want to create a jQuery statement that looks like this:
$('.total_999').html("something");
However, 999
comes from variable called storeNo
.
How can I construct this statement dynamically?
total_999 in your example is a class. Since it appears to be unique (or likely so), then it should probably be the id, and use a more generic class.
for example:
<div id="total_999" class="total">...</div>
then you can use the id, or the class to refer to the element
$('#total_'+storeNo); //get the element
or
$('.total'); //get all of the totals
A more complete example might be:
function setTotal(storeNo, total) {
$('#total_'+storeNo).html(total);
}
setTotal(999,'$1,276');