[html5] Is it safe to remove an element from within the element?
Benjamin Hawkes-Lewis
bhawkeslewis at googlemail.com
Thu Dec 22 06:32:12 PST 2011
On Thu, Dec 22, 2011 at 9:59 AM, Markus Ernst <derernst at gmx.ch> wrote:
> I have a message for non-JS UAs:
>
> <div id="jsMsg">
> <p>Javascript is turned off or not available in your browser. While
> the basic functionalities will work like this, some functions, such
> as "cancel"-buttons, might not work as expected.</p>
> <script type="text/javascript">
> var jsMsg = document.getElementById("jsMsg");
> jsMsg.parentNode.removeChild(jsMsg);
> </script>
> </div>
>
> This looks like a clean solution to me, as it is removing from the DOM both
> the element and the script to remove it. I found no problems with this code
> in Firefox 5.0 and Internet Explorer 9.
>
> Anyway, as the removing mechanism is triggered in the code before the
> element is actually closed, I ask myself whether this works by design, or
> just accidentally.
I think you'll find the <div> and <script> elements are already parsed
into the DOM before the script is executed.
--
Benjamin Hawkes-Lewis
More information about the Help
mailing list