Adding div element to body or document in JavaScript

后端 未结 9 2159
醉梦人生
醉梦人生 2020-11-27 14:14

I am creating a light box in pure JavaScript. For that I am making an overlay. I want to add this overlay to body but I also want to keep the content on the page. My current

9条回答
  •  执念已碎
    2020-11-27 14:29

    You can make your div HTML code and set it directly into body(Or any element) with following code:

    var divStr = '
    Some html
    '; document.getElementsByTagName('body')[0].innerHTML += divStr;

提交回复
热议问题