2

I am not understanding where i am going wrong. I have input as

input = '<a href="/abc/def/ghi/a00">HI </a>';

I am trying to convert it to html so i used

$('.class').html(input);

but It was not displaying properly, so i made inspect element.It was looking like

<a&nbsp;href=" abc="" def="" ghi="" a00"="">HI&nbsp;
                        </a&nbsp;href=">
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
  • `html` expects unencoded HTML. You are passing it encoded HTML. If you are expecting encoded HTML as your input, you may want to look at this question for information about how to decode it before passing it into `html`: http://stackoverflow.com/questions/1912501/unescape-html-entities-in-javascript – Marc Baumbach Sep 23 '14 at 03:30
  • 1
    It should just be `input = 'HI'` since you are adding it as html tags, and not text strings – andrex Sep 23 '14 at 03:32
  • Which version of jquery you are using? I found it is shown correctly in Firefox and in jQuery 1.6.x. jsfiddle: http://jsfiddle.net/hctkkk2n/ – masum7 Sep 23 '14 at 03:37
  • thanks @MarcBaumbach http://stackoverflow.com/a/1912522/3567511 got fixed by this. – kaustubh badamikar Sep 23 '14 at 04:49

1 Answers1

0

try this:

<div class="target"></div>
<script>
var text = '&lt;a&nbsp;href="/abc/def/ghi/a00"&gt;HI&nbsp;&lt;/a&gt;';
$('.target').html(text).text();
</script>
FMoosavi
  • 150
  • 1
  • 11