UPDATE: Seems like a browser specific behavior as TimWolla commented - how should I normalize to the unescaped version, reliably in a cross-browser manner?
HTML:
<div id="test"><a href="#{one}">#{two}</a></div>
JS:
$('#test').html()
=> <a href="#%7Bone%7D">#{two}</a>
Notice the #{one}
in the href is escaped, while #{two}
is not.
Is there a better way than just unescape
the entire string?
unescape($('#test').html())
=> <a href="#{one}">#{two}</a>
Here's the example: http://jsfiddle.net/kenn/n8veL/
First of all, I doubt if there is a reliable solution to your question. The underlying reason is simple: because the Element.innerHTML
working underneath is non-standard and it depends solely on the browser's implementation.
If you want a reliable solution, I'd suggest you use DOM operations instead of template.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With