insert/remove HTML content between div tags

后端 未结 7 1950
渐次进展
渐次进展 2020-12-30 01:22

how can I insert some HTML code between

...
using javascript?

Ex:

7条回答
  •  时光说笑
    2020-12-30 01:45

    A simple way to do this with vanilla JavaScript would be to use appendChild.

    var mydiv = document.getElementById("mydiv");
    var mycontent = document.createElement("p");
    mycontent.appendChild(document.createTextNode("This is a paragraph"));
    mydiv.appendChild(mycontent);
    

    Or you can use innerHTML as others have mentioned.

    Or if you would like to use jQuery, the above example could be written as:

    $("#mydiv").append("

    This is a paragraph

    ");

提交回复
热议问题