I have a question regarding jQuery. I am really new with jQuery, or even javascript for that matter, so please bear with me.
I am using jQuery UI draggable on some divs in my app. The problem is, jQuery .on('click') doesn't seem to work with these divs. I did try to use .click() and it does work. However, the divs are going to be created dynamically, and based on what I've learned it is best to use .on() when we want to use dynamically created elements. Below is my HTML snippet:
<div class="book-page">
<div class="draggable-text">
<p>First text</p>
</div>
<div class="draggable-text">
<p>Second text</p>
</div>
</div>
And here is the jQuery snippet:
$('div.draggable-text').draggable({
cursor: 'move',
delay: 200,
containment: 'parent'
}).resizable().selectable();
// This one doesn't work
$('div.book-page').on('click', 'div.book-page > div.draggable-text', function () {
alert('clicked!');
// some more coding here...
});
// This one works
/*$('div.book-page > div.draggable-text').click(function () {
alert('clicked!');
// some more coding here...
});*/
And lastly, here is a link to a jsfiddle I've created. I really appreciate any kind of help.
Thanks! And sorry for the bad English.