I have index.html
where there is nav menu
, header
, footer
and div.content
where jQuery parses html of page1.html
.
page1.html
loads fine, but when I add function to .nextPage2
to load page2.html
, it wont work.
page1.html
does not have head
, body
and script
.
$( document ).ready(()=> {
//Ajax
$.ajax({
url: 'page1.html',
dataType: "html",
success: function(result){
$('.content').html(result);
}});
$(".nextPage2").click(()=>{
$(".content").html("");
$.ajax({
url: 'page2.html',
dataType: "html",
success: function(result){
$('.content').html(result);
}});
})
//Ajax
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<nav class="navMenu">
<div class="container">
<div class="logo">
</div>
<ul>
<li class="page1">page</li>
<li class="page2">page</li>
<li class="page3">page</li>
</ul>
</div>
</nav>
<div class="container">
<div class="content">
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</body>
</html>
<!--page1.html
<section class="page1">
Bunch of code without head, script, body etc
<button type="button" class="nextPage2" name="button">page2</button>
</section>
-->