Suppose, in my project homepage there are some javascript code. For example,
index.html
<body>
html code here
<script type="text/javascript">
(function () {
some javascript code here
})();
</script>
<button type="button">Delete javascript</button>
</body>
Now, what I want is that, on clicking on the button all content between script tags should be deleted along with script tags. How can I do that?
Could you try putting an ID or Class on your script tag and then onlick find that ID or Class and remove it? Something like:
$('button').on('click', function() {
$('#script-tag-id').remove();
});
Try this:
window.addEventListener('load', function() { alert(document.body.innerHTML) document.getElementById('button').onclick = function() { if(document.getElementById('yourScript')){ var script = document.getElementById('yourScript'); document.body.removeChild(script); } alert(document.body.innerHTML); }; });
<body> html code here <script id="yourScript" type="text/javascript"> /*testing*/ </script> <button id="button" type="button">Delete javascript</button> </body>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.