how to remove previous js file from DOM

267 views Asked by At
(function() {

    setTimeout(function(){
        $('#core-notify').remove();
        $('#yourDynamicGeneratedScript').remove();
        $('#yourDynamicGeneratedScriptHtml').remove();

    context = $("#context").val();
        lid =  $("#userid").val();
        tid = $("#tenentId").val();
        dp_url = $("#dpUrl").val();

    var script_tag = document.createElement('script');
    script_tag.setAttribute("type","text/javascript");
    script_tag.setAttribute('id', 'yourDynamicGeneratedScript');

    script_tag.setAttribute("src",
    "https://sa.nlpbots.com/lightbot/js/light_bot.js");
      (document.getElementsByTagName("head")[0]).appendChild(script_tag);

    console.log((document.getElementsByTagName("head")[0]));

    },1000);
})(); 

This code removes a script by tag id but it only removes it from the head tag, not from the DOM file.

0

There are 0 answers