Does Setattribute Automatically Escape Html Characters?
Solution 1:
The plain English interpretation of that quote is that setAttribute()
does not parse the value as HTML. The reason for that is because you're not writing HTML at all; the value is in plain text, not HTML, so what would normally be special characters in HTML have no special meaning in plain text, and escaping them as though they were HTML would actually be destructive.
>
is the HTML representation of >
. You only need to encode it in HTML, not in plain text.
Solution 2:
Not exactly.
HTML is a data format.
Browsers will parse HTML and generate a DOM from it. It is at this point that character references (like >
) get converted to the characters they represent (like >
).
When you use setAttribute
, you directly change the DOM.
This bypasses the HTML data format entirely so the HTML foo="&"
and the JavaScript setAttribute("foo", "&")
will give you the same end result.
Post a Comment for "Does Setattribute Automatically Escape Html Characters?"