Add a span element - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:add

Description

Add a span element

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("p").add("<br><span>A new span element.</span>").appendTo("p");
    });/*w ww .j av a  2  s.c o m*/
});
</script>

</head>
<body>

<button>Add a span element</button>

<p>A p element.</p>

</body>
</html>

Related Tutorials