Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicate id within noscript

Is the following HTML/Javascript valid (strict) when Javascript is enabled? Is the id in the noscipt tag ignored?

<body>
    <noscript>
        <div id="test"></div>
    </noscript>
    <script type="text/Javascript">
        var el = document.createElement('span');
        el.id = 'test';
        document.body.appendChild(el);
    </script>
</body>
like image 713
Paul Avatar asked Jan 17 '12 19:01

Paul


1 Answers

When javascript is enabled, the content of <noscript> is raw text, not element content, so the child of the <noscript> element is a text node with value "\n <div id="test"></div>\n" instead of a DIV element. A getElementById("test") will not find a <div> with the ID "test" because there is no such element, only a text node whose content would parse to a DIV if it appeared outside a raw text context.

http://www.w3.org/TR/html5/scripting-1.html#the-noscript-element

Outside of head elements, if scripting is enabled for the noscript element
The noscript element must contain only text...

like image 176
Mike Samuel Avatar answered Sep 30 '22 23:09

Mike Samuel