In my HTML I have a div, in which I dynamically insert a collapsible with an extra button.
Here is the original HTML:
<div data-role="main" class="ui-content">
<a id="btnSearch" data-role="button" data-icon="search" data-inline="true" data-iconpos="notext"></a>
<div id='resultList'></div>
</div>
And here is the injected HTML:
<div class='resultItem' data-role='collapsible' data-id='3537' data-content-theme='c'>
<h5>Biatorbagy(65 - 312)<div><a data-role='button' class='resultZoomButton ui-btn ui-btn-icon-notext ui-icon-search ui-mini ui-corner-all ui-btn-right'></a></div ></h5>
<p class='attribution'>Year</p>
<p class='value' style='white-space:pre-wrap'>1997</p>
<p class='attribution'>Path</p>
</div>
For the extra button I would like to bind an event handler, and as there will be multple collapsible inserted, I decided to attach a delegated event handler (based on JQuery help). I added this in $(document).ready(function()) as below with JQuery's on method:
$(document).ready(function () {
$('#resultList').on('click','a.resultZoomButton',function(e){
alert(e.type + 'event fired!')
});
});
But the event handler is not called. Why?
I would think that if the div with resultList id already exists when the event handler is defined, then in the bubbling phase of the event it should filter for a elements with resultZoomButton class. (I also tried e.preventDefault() with no success.)
jsfiddle attached: http://jsfiddle.net/bsimo/5LwLmu2s/4/
JQuery: 1.9.1. JQM: 1.4.0