0

I have this line in my JS

    document.getElementById("divtry").innerHTML = jsdat;

divtry is my div in HTML and I want the content which will be displayed inside that div (the content will be different from jsdat as the special characters like &lt;br&gt; and other special characters will be converted to HTML equivalent. Ex: &lt;br&gt; will be converted to <br> )

My problem is not yet solved. my Input is this string.

     asd &lt;br&gt;sp

I need the output as below.

     asd
     sp

I am getting the output as below now.

     asd <br> sp

I tried the below code.

    document.getElementById("output").innerHTML = jsdat;
    var jsfin = document.getElementById("output").innerHTML;
    document.getElementById("o1").value = jsfin;

Output & o1 are my 2 div. But I am getting correct output in output while in o1 I'm getting the input text intself.

So, my question is, how can I get the contents inside that div divtry and assign it to some variable. Can someone please give me a function which will do that.

Evan Davis
  • 35,493
  • 6
  • 50
  • 57

1 Answers1

3

Did you try anything before asking this question?

jsdat = document.getElementById("divtry").innerHTML;
James G.
  • 2,852
  • 3
  • 28
  • 52
  • I tried that. document.getElementById("output").innerHTML = jsdat; jsfin = document.getElementById("output").innerHTML; But I'm getting Access denied error. – user3260554 Sep 02 '14 at 17:02
  • @user3260554 Are you using Internet Explorer with jQuery 1.10.1? http://stackoverflow.com/a/18702901/2640017 – James G. Sep 02 '14 at 17:06
  • I tried it. That one seems to be working. But my problem is not yet solved. my Input is this string. asd <br>sp I need the output as below. asd sp I am getting the output as below now. asd
    sp I tried the below code. document.getElementById("output").innerHTML = jsdat; var jsfin = document.getElementById("output").innerHTML; document.getElementById("o1").value = jsfin; Output & o1 are my 2 div. But I am getting correct output in output while in o1 I'm getting the input text intself.
    – user3260554 Sep 02 '14 at 17:19
  • @user3260554 can you try setting up a jsfiddle.net? – James G. Sep 02 '14 at 17:40