Skip to content Skip to sidebar Skip to footer

How To Tell JQuery A Content Editable Div Has Been Updated

I want to use jQuery to select an item that has been added to an HTML5 content editable div. It doesn't work right now because the item wasn't present when the page was loaded. How

Solution 1:

Try:

$('#editor').on('click', 'img', function() {
    $(this).fadeOut();
});​

jsFiddle example

Since you're essentially binding a dynamic element, you need to use .on() to delegate the click event on the #editor element because there is no image within the editor div when the page is loaded.


Solution 2:

You need to use .on() JQuery function to attach event to element dynamically created

Here is an example (I use body as main container, but you need to be more specific) :

$("#editor").on({
    click: function (event) {    
        console.log('test')
       $(this).fadeOut();
    }
    },
    "img"
);

Here is the fiddle http://jsfiddle.net/sjHYQ/2/


Post a Comment for "How To Tell JQuery A Content Editable Div Has Been Updated"