You cannot nest script tags. script work, the browser reads the opening tag, and then begins to collect a line of code without interpreting this code at all. He stops doing this the first time he sees the exact sequence < / s c r i p t > . The browser always stops at the first one found, and to a decisive extent, it ignores any intermediate sequence of open tags, for example, < s c r i p t > . This is due to the fact that the browser does not analyze the script code, and not its operation. This is a division of concern. ( script tags probably shouldn't be tags at all, but rather something more like a CDATA structure, but we have them.)
For example, from a browser perspective:
<script id="Product" type="text/html"> SCRIPT STARTS HERE <div class="product"> SCRIPT CODE CONTINUES .... SCRIPT CODE CONTINUES <div class="features"> SCRIPT CODE CONTINUES <script id="Features" type="text/html"> SCRIPT CODE CONTINUES (*NOT* START OF SCRIPT) <div class="feature"> SCRIPT CODE CONTINUES ... SCRIPT CODE CONTINUES </div> SCRIPT CODE CONTINUES </script> SCRIPT ENDS </div> ENDING `div` TAG (probably mis-matched) ... </div> </script> MIS-MATCHED ENDING `script` TAG
Now, if you use some kind of server template engine that replaces script tags with markup, then sends the updated markup to the browser, and then to the template engine, does it support nesting. Browsers do not.
TJ Crowder Jun 12 '11 at 2:56 a.m. 2011-06-12 14:56
source share