ID="0-0" の HTML DIV があります。そのIDを呼び出そうとするjavascriptがあります。しかし、エラーが発生しています: TypeError: Cannot set property 'innerHTML' of null
。Javascript は基本的に期待どおりに動作しないため、これをデバッグする方法がわかりません。
function getSurroundingIDs(id){
var onesPlace = parseInt(id.split("-", 2)[0]);
var tensPlace = parseInt(id.split("-", 2)[1]); //split on -, return 2 tokens
var IDs = new Array();
for (var row=onesPlace-1;row<=onesPlace+1;row++){
for (var col=tensPlace-1;col<=tensPlace+1;col++){
if(document.getElementById(row + "-" + col)){IDs[IDs.length]=row+"-"+col;}
}
}
return IDs;
}
では、なぜgetElementByID(id)
null を返すのでしょうか?