What's your take on this Javascript thingy?

Posted by Nischal on Stack Overflow See other posts from Stack Overflow or by Nischal
Published on 2010-03-21T06:08:46Z Indexed on 2010/03/21 6:11 UTC
Read the original article Hit count: 185

Filed under:
|
|

We've been having a discussion at our workplace on this with some for and some against the behavior. Wanted to hear views from you guys :

<html>
<body>
<div>
Test!
<script> document.body.removeChild(document.getElementsByTagName('div')[0]); </script>
</div>
</body>
</html>

Should the above script work and do what it's supposed to do? First, let's see what's happening here :

I have a javascript that's inside the <div> element. This javascript will delete the child node within body which happens to hold the div inside which the script itself exists.

Now, the above script works fine in Firefox, Opera and IE8. But IE6 and IE7 give an alert saying they cannot open the page.

Let's not debate on how IE should have handled this (they've accepted it as a bug and hence fixed it in IE8). The point here is since the 'SCRIPT' tag itself is a part of DOM, should it be allowed to do something like this? Should it even exist after such an operation?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about internet-explorer