getElementById succeeds once then returns null

后端 未结 2 1811
别跟我提以往
别跟我提以往 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?

提交回复
热议问题