html()
MethodYou can simply use the jQuery html()
method to replace innerHTML of a div or any other element.
The jQuery code in the following example will replace the innerHTML of a DIV element having id pageTitle
with an HTML heading on click of the button. Let's try it out:
<!DOCTYPE html>
<html lang="en">
<head>
<title>jQuery Replace innerHTML of a Div</title>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#pageTitle").html("<h1>Hello, World!</h1>");
});
});
</script>
</head>
<body>
<div id="pageTitle">
<p><b>Click the following button to replace me.</b><p>
</div>
<button type="button">Replace HTML</button>
</body>
</html>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
How to find character in string php
You can use the PHP strpos() f...Node.js MySQL Delete data Database Table
In this tutorial article, we will see ho...How to bind click event to dynamically created HTML elements in jQuery
Use the jQuery on() method...How to get form data in jQuery using serialize and serializeArray Method
jQuery serialize() method used to create...How to check whether a value is numeric or not in jQuery
Use the jQuery.isNumeric() method You...