I use the ajax.load method to replace the contents of a div. The problem is that the library I use does not allow me to replace the contents of the div, because some functions still work in the background.
In this case, I decided to delete a specific div, and then add it again, and at the last boot, the contents of the div. To do this, I created the code:
HTML:
<div id="menu1">
<ol>
<li><a href="#"><b>Choose content</b></a>
<ul>
<li id="link_1"><a href="#">Link 1</a></li>
<li id="link_2"><a href="#">Link 2</a></li>
</ul>
</ol>
</div>
<div id="container">
<div id="div_content"></div>
</div>
JQuery
<script type="text/javascript">
$(document).ready(function(){
$("#link_1").click(function(){
$("#div_content").remove();
$("#container").append("<div id='div_content'></div>");
$('#div_content').load('content1.html');
});
$("#link_2").click(function(){
$("#div_content").remove();
$("#container").append("<div id='div_content'></div>");
$('#div_content').load('content2.html');
});
});
</script>
With this code, everything works well. The point is in my Menu, I will have a large number of links to other materials. That's why I don't like having duplicate codes with .remove and .append in every link.
To do this, I created a class group for objects, and I use .remove and .append for specific .class and .load for a specific link identifier.
<div id="menu1">
<ol>
<li><a href="#"><b>Choose content</b></a>
<ul class="clear_div1">
<li id="link_1"><a href="#">Link 1</a></li>
<li id="link_2"><a href="#">Link 2</a></li>
</ul>
</ol>
</div>
<div id="container">
<div id="div_content"></div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$(".clear_div1").click(function(){
$("#div_content").remove();
$("#container").append("<div id='div_content'></div>");
});
$("#link_1").click(function(){
$('#div_content').load('content1.html');
});
$("#link_2").click(function(){
$('#div_content').load('content2.html');
});
});
</script>
, .load .remove .append.
.load .remove .append?