When running my code, only two of the document.getElementById calls (ctx1 and ctx2) successfully get values while the others (such as ctx3) do not. How can I ensure that all elements retrieve their values without receiving an error message? Below is a snippet from my code:
CODE SNIPPET
var ctx1=document.getElementById("data1").getContext("2d");
var ctx2 =document.getElementById("data2").getContext("2d");
var ctx3 =document.getElementById("data3").getContext("2d");
Currently, ctx1 and ctx2 receive values while ctx3 does not, resulting in a "document.getElementById(...) is null" error message in the console. I have made some attempts to fix this issue but none have been successful.
ATTEMPTS MADE
1
if(ctx3 === null ||
ctx3 === undefined) {
return true;
}
2
if(document.getElementById("data3")..getContext("2d").value == null){
return true;
}