I currently have code that does this:
$('#BoxShadow_1').click(function()
{
addDivBoxShadow('BoxShadow_1');
});
$('#BoxShadow_2').click(function()
{
addDivBoxShadow('BoxShadow_2');
});
...etc for 10 similar elements. It works just fine.
I am using JQuery also.
I want to change the code to something like this:
for (i = 1; i < 11; i++) {
$('#BoxShadow_' + i).click(function(){
addDivBoxShadow("BoxShadow_" + i);
});
}
Challenge is this:
BoxShadow_10 is assigned to all of the divs rather than BoxShadow_1, BoxShadow_2 etc.
FYI the code I am trying to effect is a math game I wrote at this URL:
tinyurl.com/sashamath
Thanks in advance. And I hope to contribute in the future.
Ok, so here is the answer, using the 'let' statement as follows:
for (let i = 1; i < 11; i++) {
$('#BoxShadow_' + i).click(function(){
addDivBoxShadow("BoxShadow_" + i);
});
}