P粉0879514422023-08-22 09:15:10
Use appendChild:
var theDiv = document.getElementById("<ID_OF_THE_DIV>"); var content = document.createTextNode("<YOUR_CONTENT>"); theDiv.appendChild(content);
Use innerHTML:
As @BiAiB reminds me, this method will remove all listeners for existing elements. So if you plan to use this version, please proceed with caution.
var theDiv = document.getElementById("<ID_OF_THE_DIV>"); theDiv.innerHTML += "<YOUR_CONTENT>";
P粉1904436912023-08-22 00:14:03
Try this:
var div = document.getElementById('divID'); div.innerHTML += '额外的内容';