Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery cannot grab html contenteditable val

Tags:

html

jquery

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

like image 969
t q Avatar asked May 27 '12 03:05

t q


2 Answers

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>
like image 122
coolguy Avatar answered Sep 28 '22 01:09

coolguy


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

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

like image 31
Sampson Avatar answered Sep 28 '22 02:09

Sampson