views:

29

answers:

3

I am trying to assign a value like <div> a value </div> to an html element say textarea in chrome browser, but the value is not getting assigned. It works fine if i try to assign a plain text like a value

I am using this

$('#editor').html((content));

where content = <div> a value </div>

Please help me in solving this issue. Is it chrome not allowing to assign the html value or some thing different?

A: 

use this code to assign value or html to a div using jquery

$('#editor').append('<div> a value </div>');

or

content = '<div> a value </div>';
$('#editor').append(content);
Jaison Justus
i tried using this, but no luck
let me check it.
Jaison Justus
yes i got the same problem but running this piece of code it works!!!!!!<!DOCTYPE html><html><head> <style>#test {width:100px; height:100px;} p { background:yellow; }</style> <script src="http://code.jquery.com/jquery-latest.min.js"></script></head><body> <div id="test"></div> <p>I would like to say: </p><script> $("p").append("<strong>Hello</strong>");</script></body></html>
Jaison Justus
A: 
$("#editor").html($("<div>").text("<div>a value</div>").html());​

Check here : http://jsfiddle.net/MkBSP/1/

Kaaviar
A: 

Don't mess with the innerHTML of a textarea, set its value instead.

David Dorward
Thanks it worked for me, instead of setting the innerhtml i am now setting the value