Reputation: 4102
I try to find a way to disable the following scenario:
<div>
<span>
</div>
Html will autocomplete the missing </span>
, Is there a way?, Maybe a tag?, Anything to disable this behavior inside the <div>
tag?
Is there a way to disable this behavior via javascript?
Upvotes: 0
Views: 425
Reputation: 2429
Your problem is not that "HTML autocompletes the missing </span>
". If your browser wouldn't do that, your page would be completely broken. What you really want to do is to tell the browser to stop parsing the page.
There is no way to disable parsing inside of an element. What you can use, though, are HTML escape characters. They tell the browser that you want to display characters like <
and >
instead of using them as HTML code.
<
with <
(less than)>
with >
(greater than)<div>
<span>
</div>
You will see this in your browser:
<span>
If you have a string in Javascript that contains HTML code that you want to display on your page, you can use innerText
to insert it into an element. All characters will be replaced by their escaped versions, if necessary.
var code = '<div class="mydiv">',
outer = document.getElementById("outer");
outer.innerText = code;
Upvotes: 3