2

Problem:

I'm interested to bind the click event of all children of a dynamically generated div.

Understandings:

Binding as of 1.7

$(staticAncestors).on(eventName, dynamicChild, function() {...

example:
$('body').on('click','.myDiv', function() {...

Using * as selector binds to ALL ELEMENTS

$('.myDiv').on('click', '*', function() {...

Question:

How would I bind the * to a dynamically generated div?

've replicated my project in a jsfiddle.

NOTE: In Ahmad's jsfiddle (see the first answer), the child click events work WITH or WITHOUT the * included in the on click selector. In my jsfiddle, my example works fine (when the * isn) if you click the PARENT div, but clicking on CHILD elements (image and text title) does not. Now, add the * to my example, and nothing works...

cpardon
  • 467
  • 4
  • 22

1 Answers1

4

I just tried what I asked you in the comments and it worked:

$('body').on('click','.myDiv *', function() {

here's an example: http://jsfiddle.net/rfdwrrma/3/

duxfox--
  • 8,314
  • 13
  • 50
  • 112
  • agreed, this works in your jsfiddle. Not sure why adding this * into my class '.seq_btn' to '.seq_btn *' has totally disabled the event now – cpardon Jul 25 '15 at 03:24
  • maybe depends on jquery version or you have something else going on. or you have a typo. Idk, post your click event code to your question so we can see it. and maybe your html code might be helpful too (just the relevant part) – duxfox-- Jul 25 '15 at 03:25
  • I've replicated my project in a jsfiddle. NOTICE: In your jsfiddle, the child click events work WITH or WITHOUT your `*` included in the on click. WITHOUT the `*`, my example works fine if you click the PARENT div, but clicking on CHILD elements (image and text title) does not. Now, add the `*` to my example, and nothing works... – cpardon Jul 25 '15 at 05:20