how to tag

Asked

Viewed 31 times

-3

i have the tags

<!DOCTYPE html>

<html>
    <head>

    </head>
    <body onload="">
        <script src="data/js/main/engine.js"></script>
        <script src="data/js/main/canvas.js"></script>
        <script src="data/js/main/main.js"></script>
    </body>
</html>

and I have a code to add new scripts

function Script(src=""){
    this.script=document.createElement("script")
    this.load=function(){
        this.script.src=src;
        document.body.appendChild(this.script);
    }
    this.deload=function(){
        this.script.src=null;
        document.body.removeChild(this.script);
    }
}

so the part of removing the script doesn’t work as I can remove the script from the body tags

1 answer

0


You can use the logic of calling the parent element with .parentNode and then use the .removeChild() in the element you want to remove.

this.script.parentNode.removeChild(this.script);
  • worth you helped me a lot

Browser other questions tagged

You are not signed in. Login or sign up in order to post.