getElementById succeeds once then returns null

后端 未结 2 1773
别跟我提以往
别跟我提以往 2021-01-28 04:33

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

相关标签:
2条回答
  • 2021-01-28 04:59
    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?

    0 讨论(0)
  • 2021-01-28 05:00

    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.

    0 讨论(0)
提交回复
热议问题