user3260554
user3260554

Reputation: 5

copy the content inside a div to a variable

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.

Upvotes: 0

Views: 1115

Answers (1)

James G.
James G.

Reputation: 2904

Did you try anything before asking this question?

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

Upvotes: 3

Related Questions