jQuery – add text to existing div

jQuery .append() can be used to add text to an div. The text can contains tags inside it.

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>

<div style="background-color:lightblue;" id="msg">First line<br></div>

<button onclick="addText()">click to add text</button>

<script type="text/javascript">
function addText() {
  $("#msg").append("Added text<br>");
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments