I have this code to generate n amount of divs with id based on their x and y position:
$("#gameContent").append($("<div></div>").attr("id", "board"));
var card;
for (var y = 0; y < clientBoard.length; y++) {
for (var x = 0; x < clientBoard.length; x++) {
if(clientBoard[y][x] == undefined){
continue;
}
card = $("<div></div>").addClass("card");
card.attr("id", (y + ":" + x));
card.html("Value " + clientBoard[y][x].value);
if (x == 0) {
card.addClass("clearleft");
}
$("#board").append(card);
}
}
This works and when i inspect in chrome all divs have their correct (e.g "1:2"). Then I want to use the HTML() function to change the content of those divs. But when using:
console.log($("#" + y + ":" + x).html());
It prints undefined
I will use this code to update the html content for the divs:
for (var y = 0; y < clientBoard.length; y++) {
for (var x = 0; x < clientBoard.length; x++) {
if(clientBoard[y][x] == undefined){
continue;
}
$("#" + y + ":" + x).html("Value: " + clientBoard[y][x].value);
}
}
I have tried to google and look at the documentation of the html(), but can't seem to find anything that is wrong. I used the html() earlier in my code, only difference is the selector there was just a string and not a combination of string and a variable. That worked great.
I also printed all the selectors it tried to use and compared them with the id of the divs, and they are correct.
I have also tested and printed the value that it tries to put into the divs, that also worked
Ask if I should provide more information.
:is a special character and will need to be escaped in the selector.