I'm using an ajax method .load to replace a content of a div. The problem is because a library which I'm using doesn't allows me to replace content of a div because some functions still working in the background.
In this case I decided to remove a specific div and then add it again and on the last load a content of a div. For this I created a 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 thing is in my Menu i will have a big number of links to others contents. Thats why i don't like to have repetitive codes with .remove and .append in every link.
For this I created .class group for objects and I'm using .remove and .append for specific .class, and .load function for specific link id.
<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> In this code problem is that always .load function is executed before functions .remove and .append. Do You have any idea how to make function .load executed after .remove and .append ?