Is it possible to append to innerHTML without destroying descendants' event listeners?

前端 未结 13 1159
悲哀的现实
悲哀的现实 2020-11-21 23:40

In the following example code, I attach an onclick event handler to the span containing the text \"foo\". The handler is an anonymous function that pops up an <

相关标签:
13条回答
  • 2020-11-22 00:29

    I'm a lazy programmer. I don't use DOM because it seems like extra typing. To me, the less code the better. Here's how I would add "bar" without replacing "foo":

    function start(){
    var innermyspan = document.getElementById("myspan").innerHTML;
    document.getElementById("myspan").innerHTML=innermyspan+"bar";
    }
    
    0 讨论(0)
提交回复
热议问题