How to replace content in div using Jquery

author details
AdiPie
23rd Dec 2020
1 min read
Image
replace-content-using-div

For that we can use the jQuery html() method to replace inner content of a div or other element.

<script>
$(document).ready(function(){
    $("button").click(function(){
        $("#custom_id").html("<h1>My Custom Text</h1>");
    });
});
</script>

<div id="custom_id"><p>Click the following button to replace me.<p></div>
<button type="button">Replace HTML</button>