0

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.

5
  • 1
    Why not just disable and then reenable javascript in the browser? Commented Apr 18, 2013 at 18:27
  • Just get its contents and put it in a <div> on the page Commented Apr 18, 2013 at 18:28
  • That doesn't actually show <noscript> working though :/ Commented Apr 18, 2013 at 18:31
  • @Xotic750 That's not what the OP asked for. They asked if it's possible to toggle its visibility for demonstration purposes. Commented Apr 18, 2013 at 18:45
  • No, they ask: Is it possible to invoke the <noscript> element even when JavaScript is enabled? Commented Apr 18, 2013 at 18:59

2 Answers 2

3

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);
Sign up to request clarification or add additional context in comments.

4 Comments

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.
@ŠimeVidas That's not bad approach. That is not fast but short approach.
@ŠimeVidas From what I remember, with JS enabled noscript's contents are text nodes only and not DOM elements.
@FabrícioMatté I see. The entire content of a <noscript> element is represented by one Text node. In that case, the approach is OK.
-1
<noscript>stuff</noscript>
<div id="mydiv"><div>

$('#mydiv').text($('noscript').text());

http://jsfiddle.net/5pDBT/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.