s_p
s_p

Reputation: 4693

jQuery cannot grab html contenteditable val

i have a div with contenteditable="true" that im using in place of textarea
using jQuery, i cant seem to capture its val()
heres my fiddle
thanks

Upvotes: 6

Views: 7837

Answers (4)

Rahmuna
Rahmuna

Reputation: 232

Change the line from....

var mypost = $('#myTextArea').val();

to

var mypost = $('#myTextArea').text();

Upvotes: 0

coolguy
coolguy

Reputation: 7954

Some general tips even if you got the answer

.val() = getting value from elements like text,textarea,select,checkbox

.text() = getting text values(excludes html tags) from elements like text,textarea,select,checkbox

.html() = getting html content from elements like span,div p table..etc..

Examples

<input type="text" id="someid" value="1234" />
$('#someid').val(); //1234
<p>bla bla bla<span>hello</span></p>
$('p').text(); //bla bla bla
$('p').html(); //bla bla bla<span>hello</span>

Upvotes: 12

WojtekT
WojtekT

Reputation: 4775

This is not textarea but div therefore cannot be read with val().

Upvotes: 1

Sampson
Sampson

Reputation: 268344

With it being a div, you would grab the .text().

Fiddle: http://jsfiddle.net/jPD7y/4/

Upvotes: 9

Related Questions