jQuery isn't escaping anything, in fact your string is literally set as the title. You can
simply use:
$("div").attr('title','foo
bar')
http://jsfiddle.net/t5DvY/
There seems to be a whole lot of misunderstanding what escaping means. What you are doing is completely unnecessary.
Escaping is only necessary in a context where the character would otherwise have a special meaning and you want it not to have any special meaning.
For example, in the eyes of html parser, <
is special. You have to replace it with <
if you want to ensure it is treated as literal
<
. Emphasis on in the eyes of html parser. In javascript, <
is not special in a string in any way, thus you could
do elem.setAttribute("title", '""><b>hi</b>')
and that's what you get, the element's title will literally be ""><b>hi</b>
.
As for html code point references, they are generally useless. You can simply use literal characters. Instead of writing ♥
, you can simply
write ?
. Instead of writing ö
, you can simply write ?
. Here's http://jsfiddle.net/fnqDn/2/.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…