How to Add Content in jQuery

Add a new HTML Content :-

How to Add Content in jQueryexpoundsofttechsolution What is GMT?

Four jQuery Methods are used to add new content.

  1. append() – put content at the end of the selected elements
  2. prepend() – put content at the beginning of the selected
    elements
  3. after() – put content after the selected elements
  4. before() – put content before the selected elements

append() Method:-

The jQuery append() method put content AT THE END of the selected HTML elements.

Example:-

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#button").click(function(){
    $("p").append(" <b><i>Appended</b></i>.");
  });
});
</script>
</head>
<body>
<p>This is a Append Method.</p>
<button id="button">Append</button>

</body>
</html>

OUTPUT:-

when we will click the append button, then the append text will add.