0

I am trying to build a site that dynamically loads the pages. Certain pages have extra javascript that they load. I need to be able to unload this javascript when the page changes. Is that possible? My code so far (work in progress still):

//When page loads...
$("ul.toggle li:first").addClass("active").show(); //Activate first tab
var taburl = $("ul.toggle li:first a").attr("href").substr(1);
$(document).ready(function(e) {
    $.ajax({
        type: "POST",
        url: taburl+'.php',
        data: '',
        dataType: "html",
        success: function(d){
            $('#main').html(d);        
    }       
});
});

//On Click Event
$("ul.toggle li").click(function() {

    $("ul.toggle li").removeClass("active"); //Remove any "active" class
    $(this).addClass("active"); //Add "active" class to selected tab
    $("#main").fadeOut(500);
    $("#main").html('');

    var activeTab = $(this).find("a").attr("href").substr(1) + '.php'; //Find the href attribute value to identify the active tab + content
    $("#main").load(activeTab).fadeIn(500); //Fade in the active ID content
});

Let me know if any other info is needed.

watzon
  • 2,401
  • 2
  • 33
  • 65
  • possible duplicate of [How can I dynamically unload a javascript file?](http://stackoverflow.com/questions/591685/how-can-i-dynamically-unload-a-javascript-file) – maxedison Apr 08 '13 at 18:50
  • already looked at that – watzon Apr 08 '13 at 18:53
  • If the purpose of unloading the javascript is to prevent it from conflicting with the new javascript, that's not at all what unloading it will do. – Kevin B Apr 08 '13 at 18:53
  • that's what I want to figure out how to do. I need to figure out how to remove the javascript from the browser memory so that the new javascript doesn't conflict – watzon Apr 08 '13 at 18:55
  • well that possible duplicate answers your question: http://stackoverflow.com/a/6927290/411954 – maxedison Apr 10 '13 at 17:12

0 Answers0