I've recently learn about the use of xmp tag, that it is deprecated, and a lot of people says to use pre, or to translate special characters with <
, >
, etc.
... but those solutions are not good in my case.
Actually, i would like to put content in a webpage, and that this content was not interpreted until i copy it, with JavaScript, into an other container.
For now i've found only one solution, which is not realy clean :
<div id="myContent" class="hidden">
<!--MyContent-->
</div>
Then, via Javascript, i parse the content to remove the comment html tags.
Have you found better solutions to do that?
Note
The xml data island approach has become obsolete since the authoring of this answer. This is mirrored in the MDN docs which retired the pages discussing the details.
However, using html5 data blocks - actually the gist of this answer - is a more general technique in the same vein (allowing for data blocks of different types than just xml, eg. json).
See this page for discussion.
Answer proper
Use html data islands to store arbitrary data in your html. The following samples show some variations:
The script
tags can be accessed from javascript and universal attributes like id
may be added to simplify access.
<!-- xml -->
<script type="text/xml">
<data>
<!-- whatever -->
</data>
</script>
<!-- html -->
<script type="text/html">
<a href="http://example.com">example.com</a>
</script>
<!-- plain text -->
<script type="text/plain">
whatever
</script>
<!-- plain text in an xml cdata section (text mustn't contain ']]>') -->
<script type="text/xml">
<plain><![CDATA[...whatever...]]></plain>
</script>
There used to be an article on MDN discussing the technique which has been retired (see initial note of this answer). See here instead.