How can i catch the object is null or not an object. Actually i have wrote this line in if condition for solving it, but not working.
But Generating ERROR :- "object is null or not an object"
var preWynum = "";
function paint(Wynum)
{
// alert("Wynum:"+Wynum +", preWynum:"+preWynum);
if(document.getElementById(preWynum) && document.getElementById(Wynum开发者_运维知识库))
{
document.getElementById(preWynum).style.backgroundColor='white';
document.getElementById(Wynum).style.backgroundColor='yellow';
}
preWynum = Wynum;
}
I dont believe why it not running. Any other idea ?
preWynum and Wynum is the id of tr(table row).
I want to set background color with yellow to current selected row(that's id is Wynum).
The error is because you are passing an object (non-existent) to getElementById()
when it expects a string:
// Put quotes around 'preWynum' and 'Wynum'
if(document.getElementById('preWynum') && document.getElementById('Wynum'))
{
document.getElementById('preWynum').style.backgroundColor='white';
document.getElementById('Wynum').style.backgroundColor='yellow';
}
精彩评论