Suppose I have a markup like this
<div class="container">
<div class="abc" onclick="alert(this.innerHTML)">ABC</div>
<div class="abc1">ABC</div>
<div class="abc2">abc2</div>
<div class="xys3">xys3</div>
<div class="asd23">asd223</div>
</div>
And there are events which are bind to the children
of a container
like this
$( ".abc1" ).bind( "click", function(){
alert( $( this ).html() );
} );
$( ".abc2" ).bind( "click", function(){
alert( $( this ).html() );
} );
$( ".xys3" ).bind( "click", function(){
alert( $( this ).html() );
} );
$( ".asd23" ).bind( "click", function(){
alert( $( this ).html() );
} );
Now, I get the html out of container and set it back again :
var html = $( ".container" ).html();
// a set missing here to convert 'bind' events to 'on' events
$( ".container" ).html( html );
Events won't work now since they were not delegated to start with. Also, container may be having more elements (they are dynamic).
Is it possible to find all events inside a container and delegate them?
Here is a Fiddle