jQuery syntax for multiple delegated events -
the jquery docs @ http://api.jquery.com/on/ mention benefits of delegated-events using following syntax (which attaches event handler 1 element):
$('#mytable').on('click', 'tr.hoverable', function(){ // blah });
but can't find reference proper syntax attaching multiple events @ once delegated-events. there shortcut following, tr.hoverable delegated event?
$('#mytable tr.hoverable').on({ mouseenter: function(){ // blah }, mouseleave: function(){ // blah }, click: function(){ // blah } });
or solution ...
$('#mytable').on('click', 'tr.hoverable', function(){ // blah }).on('mouseenter', 'tr.hoverable', function(){ // blah }).on('mouseleave', 'tr.hoverable', function(){ // blah });
?
$('#mytable').on({ mouseenter: function(){ // blah }, mouseleave: function(){ // blah }, click: function(){ // blah } }, '.hoverable');
.on( events-map [, selector] [, data] )
also, prefer single tagname/classname/id selectors delegation optimized
Comments
Post a Comment