Adding an img element to a div with javascript

后端 未结 4 1563
囚心锁ツ
囚心锁ツ 2020-11-29 02:54

I am trying to add an img to the placehere div using JavaScript, however I am having no luck. Can anyone give me a hand with my code?



        
4条回答
  •  感情败类
    2020-11-29 03:22

    document.getElementById("placehere").appendChild(elem);
    

    not

    document.getElementById("placehere").appendChild("elem");
    

    and use the below to set the source

    elem.src = 'images/hydrangeas.jpg';
    

提交回复
热议问题