Как заменить innerHTML div с помощью jQuery
Вы можете просто использовать метод jQuery html()
для замены innerHTML элемента div или любого другого элемента.
Код jQuery в следующем примере заменяет innerHTML элемента DIV с идентификатором pageTitle
заголовком HTML при нажатии кнопки:
<!DOCTYPE html>
<html lang="en">
<head>
<title>jQuery Replace innerHTML of a Div</title>
<script src="https://code.jquery.com/jquery-3.5.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>