I’m making a webpage and want to show a preloader before loading the rest of it. I want only my first <head> tag to be parsed by the browser and the rest to be ignored. This would be ideal:
<head>
<script src='preloader.js'></script>
<script src='more1.js' ignore='true'></script>
<script src='more2.js' ignore='true'></script>
<script src='more3.js' ignore='true'></script>
</head>
This drove me to wonder how it might be possible to have existing, latent HTML tags on my page, that I mark later by JavaScript to activate them, like uncommenting them. I was thinking commented code would be the answer, but I wasn’t able to read my HTML comments from jQuery’s DOM.
How can I create latent HTML that I activate later?
I’m not looking to:
– Have valid HTML.
– Inject HTML content residing outside of its own file (changing stuff, like an attribute would be ok).
– Unhide anything that has already been parsed.
You’ll have to clarify a little bit: do you want the HTML to not be parsed or not be displayed?
If you don’t want it to be parsed, plunk it in a JavaScript string in a script element:
If you don’t want it to be displayed, set
display:noneon the inline styles (this prevents any issues that may happen with css):In either case you can access the node later with jQuery using
$(yourHTML)and$('#whatever')respectively.