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.

5
  • possible duplicate of How can I dynamically unload a javascript file? Commented Apr 8, 2013 at 18:50
  • already looked at that Commented Apr 8, 2013 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. Commented Apr 8, 2013 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 Commented Apr 8, 2013 at 18:55
  • well that possible duplicate answers your question: stackoverflow.com/a/6927290/411954 Commented Apr 10, 2013 at 17:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.