Home > Article > Web Front-end > How to Append Text to a DIV Element with AJAX?
Appending Text to a DIV Element with AJAX
When using AJAX to dynamically populate a DIV element with data from JavaScript, it's common to want to append new data without losing existing content. To achieve this, follow the below steps:
var div = document.getElementById('divID'); div.innerHTML += 'Extra stuff';
This code will append the text "Extra stuff" to the existing content of the DIV with the ID "divID". The innerHTML property can also be used to replace existing content if desired.
The above is the detailed content of How to Append Text to a DIV Element with AJAX?. For more information, please follow other related articles on the PHP Chinese website!