Is it possible to invoke the <noscript> element even when JavaScript is enabled? I need to toggle it's visibility for demonstration purposes of what it will look like.
2 Answers
You can create a new <div> element with contents from the <noscript> and then remove it after demonstration:
// to create
var div = document.createElement("div");
div.innerHTML = document.getElementsByTagName("noscript")[0].innerHTML;
document.body.appendChild(div);
// to remove
document.body.removeChild(div);
4 Comments
Šime Vidas
That's a bad approach. You're serializing and de-serializing the data, just to move it from one element to another. DOM manipulation methods should be used instead.
VisioN
@ŠimeVidas That's not bad approach. That is not fast but short approach.
Fabrício Matté
@ŠimeVidas From what I remember, with JS enabled
noscript's contents are text nodes only and not DOM elements.Šime Vidas
@FabrícioMatté I see. The entire content of a <noscript> element is represented by one Text node. In that case, the approach is OK.
<noscript>stuff</noscript>
<div id="mydiv"><div>
$('#mydiv').text($('noscript').text());
<div>on the page