How to prevent jQuery.html () from automatically escaping the href attribute?

The UPDATE . Looks like the browser behavior TimWolla commented on - how should I normalize to an unlimited version, reliably in a cross browser?

HTML:

<div id="test"><a href="#{one}">#{two}</a></div>

JS:

$('#test').html()
=> <a href="#%7Bone%7D">#{two}</a>

Note that #{one}in href it is escaped, but #{two}not.

Is there a better way than just a unescapewhole line?

unescape($('#test').html())
=> <a href="#{one}">#{two}</a>

Here is an example: http://jsfiddle.net/kenn/n8veL/

+5
source share
2 answers

First of all, I doubt that there is a reliable solution to your question. The main reason is simple: since it works under Element.innerHTMLnon-standard and depends solely on the implementation of the browser.

, DOM .

+1

JavaScript , "href" .

<a href='#dummy' data-href='#{template}'>Hi</a>

data "href".

0

All Articles