jQuery add() add to <p> then append to <p>

Description

jQuery add() add to <p> then append to <p>

View in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").add("<br><span>A new span element.</span>").appendTo("p");
  });//from   www  .j  ava2s . c o  m
});
</script>

</head>
<body>

<button>Add a span element</button>

<p>A p element.</p>

</body>
</html>



PreviousNext

Related