When you click on the button "test", Ajax takes the code in the file "second.html" and updates the content in the main page "main.html". When you click on the button "test__second", the script returns the content to the main page, but when you repeat the action, this button will not work, i.e its request only works once, but I want it to always work. Any suggestions?
Here is main.html:
<div class="container">
<div class="test">Click</div>
<div class="center">This is the main page</div>
</div>
And here is second.html from where the ajax takes the content:
<div class="test__second">Click</div>
<div class="center__second">This is second page</div>
<script>
$(document).ready(() => {
$.ajax({
async: false,
type: 'GET',
url: './setts.js',
data: null,
dataType: 'script'
});
});
</script>
JavaScript file (setts.js):
$(document).ready(() => {
$('.test').click(() => {
$.ajax({
async: false,
url: './second.html',
cache: false,
dataType: 'html',
success: function(html) {
$('.container').html(html);
}
});
});
$('.test__second').click(() => {
$.ajax({
async: false,
url: './index.html',
cache: false,
dataType: 'html',
success: function(html) {
$('.container').html(html);
}
});
});
});