Reputation: 6512
I have a piece of javascript code that I wrote to grab the html of a certain dom element, the problem is there is another element inside that dom element and it's rendering as html.
example:
<p>
test.append("<ul />");
</p>
Is there a way to ignore the ul inside the p without having to replace < with <
and things of that sort?
The javascript code I wrote just takes the current text in the provided dom and places code lines next to it. Such as an IDE would.
Upvotes: 1
Views: 696
Reputation: 5580
In XHTML and HTML 5, you can use CDATA sections so that you don't have to escape critical characters:
<p>
<![CDATA[
test.append("<ul />");
]]>
</p>
Update: I don't know of any method to achieve that for HTML <= 4 documents. CDATA is implicitly assumed for e.g. <script>
content, but certainly not for <p>
. However, why not properly escape characters (e.g. <
-> <
) in the first place? If your content is static, your text editor might help you with that; if it is dynamic (generated by PHP or whatever), there are functions to do that for you.
Upvotes: 2