.InnerHTML Not working properly in Internet Explorer

后端 未结 10 1573
一个人的身影
一个人的身影 2020-12-19 08:55

I wanted to assign a link tag to innerHTML of a HTML control. But this is not working properly in Internet Explorer. However when I try to assign anything other than &

10条回答
  •  北海茫月
    2020-12-19 09:43

    A lot of people are missing the point here. What he is trying to do ( after fixing the typo where the href attribute is missing ) works in any other browser.

    IE 8 and below have a bug where if the first element in the text when setting innerHTML is a tag (maybe others), it is ignored. If you just put a space or newline or other tag first, it works.

    He even discovered this when he said putting the

    first fixes it.

    It isn't valid, but that's how you fix it.

    Edit: in other words: foo.innerHTML = "\n" + yourHtmlWithLinkInIt;

提交回复
热议问题