I have a simple list of contenteditable
divs
and I want to add new divs
with a button and get the value of the contentediable
like this:
HTML
<input type="button" id="addItem" value="Add item" />
<div class="itemContainer">
<div class="item" id="item1" contenteditable="true">
Item 1
</div>
<div class="item" id="item2" contenteditable="true">
Item 2
</div>
</div>
Javascript
$(function() {
$("#addItem").click(function() {
$(".itemContainer").append('<div class="item" id="item3" contenteditable="true">Item 3</div>');
});
$("[contenteditable]").blur(function() {
console.log($(this).html());
});
});
Fiddle
The problem is that the console.log
does not show the value of the contenteditable div
after I pushed the button Add Item
The first 2 items are working properly.
How can I access the contenteditable
in case of I have appended it to the DOM?
Any help is appreciated!
Thanks!