Skip to content Skip to sidebar Skip to footer

Getelementbyid Succeeds Once Then Returns Null

I'm new to javascript and this is driving me nuts. I'm attempting to set the text and color of a label ('lblerrmsg') depending upon the value of a flag ('IsValid'). I've written a

Solution 1:

ErrMsg.outerHTML = 'valid';

If you do that, you have destroyed the previous ErrMsg and the new content will not have the id anymore (so that it cannot be found by getElementById).

Are you sure you don't want innerHTML?

Solution 2:

try to change the class name of the div or element to change the css style if you want

document.getElementById("blah").className = "cssclass";

this way you can control the css depending on the flag of yours.

Post a Comment for "Getelementbyid Succeeds Once Then Returns Null"