I can listen to all mrow click events of a div, using sometihng like
$('#mydiv').on('click', 'mrow', function() {
var moo = $(this).attr('id');
if (handlers[id]) {
event.stopPropagation();
handlers[id]();
}
Can I use a similar setup to listen on all click events of all the children of the div (Without setting up, separate listeners for every type)? Some part of the tree have handler functions and some don't, and I want these requests to propagate up within the div, until one that has a handler is found.
$('#mydiv').on('click', '*', function() {
*
will bind to all element's within #mydiv
Demo -->
http://jsfiddle.net/Vjwqz/1/
For all descendants:
$('#mydiv').on('click', '*', function() {...});
For direct descendants: {what is called children in javascript}
$('#mydiv').on('click', '> *', function() {...});
I think you can leave the selector
$('#mydiv').on('click', function() {
selector Type: String A selector string to filter the descendants of the selected elements that trigger the event. If the selector is null or omitted, the event is always triggered when it reaches the selected element.
http://api.jquery.com/on/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With