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:
Hey fellow developers! Today, let's tackle the installation of the PHP SOAP extension on our Ubuntu 23.04 systems. I...
Jan-31-2024
In this tutorial I will show you laravel 8 send mail using queue, many time we can see some process to take mo...
Sep-24-2021
In this article, we will see 500 internal server errors in laravel 9 ajax. Also, we can see how to solve or fixed l...
Apr-17-2022
In this tutorial we will see how to generate pdf and send email in laravel 8. For generating PDF file we will use l...
Dec-20-2021