How To Replace innerHTML of Div Using jQuery

Websolutionstuff | Jul-08-2022 | Categories : jQuery

In this article, we will see how to replace the innerHTML of div using jquery. We can use html() method to replace the innerHTML of the div or any other HTML element. The html() method sets or returns the content (innerHTML) of the selected elements.

So, let's see how to replace html of div using jquery, jquery replace html in div, how to add html in div using jquery, how to change div text in jquery, jquery replace innerHTML, jquery get innerHTML, jquery replace html.

The jQuery code in the following example will replace the innerHTML of a DIV element having id changeTextDiv with an HTML heading on click of the button.

<!DOCTYPE html>
<html lang="en">
<head>
<title>How To Replace innerHTML of Div Using jQuery - Websolutionstuff</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
$(document).ready(function(){
    $("#changeTextBtn").click(function(){
        $("#changeTextDiv").html("<h1>Hello, World!</h1>");
    });
});
</script>
</head>
<body>
    <div id="changeTextDiv">
        <p><b>Click the following button to replace me.</b><p>
    </div>
    <button type="button" id="changeTextBtn">Replace HTML</button>
</body>
</html>

 


You might also like:

Recommended Post
Featured Post
How To Validate Email Using jQuery
How To Validate Email Using jQ...

In this article, we will see how to validate email using jquery. we will use regular expression(regex) for email va...

Read More

Nov-09-2022

How To Get Selected Checkbox List Value In Jquery
How To Get Selected Checkbox L...

In this tutorial, I will explain you to how to get the selected checkbox value from a checkbox list in jquery, If y...

Read More

Jun-17-2020

How To Send Email Using Markdown Mailable Laravel 9
How To Send Email Using Markdo...

In this article, we will see how to send email using markdown mailable laravel 9. we will learn laravel 9 to s...

Read More

Aug-05-2022

How to Add Date Picker in React JS using react-datepicker
How to Add Date Picker in Reac...

A date picker is a crucial component in many web applications, enabling users to select dates conveniently. React, a pop...

Read More

Sep-11-2023