<script>var blah = "blah" ;</script> <script> var script = document.getElementsByTagName("script")[0] ; script.parentNode.removeChild(script) ; alert(document.querySelector("script").innerHTML) ; </script>