So I am trying to find the answer to this, but there seems to be no definitive one I can find to help me make the right choice.
So What I am curious about is $.delegate()
as of recently I am a fan of using it, seems to be a bit more stable in most of my apps now a days. So with that. I typically when using it will do something like
$('div').delegate('.someclass', 'click', function(e){ .... });
and I am good with that, until now. Where I have an element that I need to handle multiple events for. So I am wondering whats the best approach? do I do something to the extent of.
$('div').delegate('.someclass', 'click', function(e){ .... });
$('div').delegate('.someclass', 'mouseover', function(e){ .... });
$('div').delegate('.someclass', 'mouseout', function(e){ .... });
or do I go the $.bind()
route? and do something like
$('.someclass').bind({
click:function(){...},
mouseout:function(){...},
mouseover:function(){...}
});
does $.delegate()
support something similar to $.bind()
? It doesn't appear so reading through the API but ya never know (doesn't work for me). Or is there a function I simliar in nature to the combination of the two that I might not be aware of?
.delegate
and .bind
have been superseeded by on.()
as of jQuery ver 1.7
$('div').on({
click:function(){...},
mouseout:function(){...},
mouseover:function(){...}
},'.someclass');
$('div').on( 'click mouseover mouseout','.someclass', function(e){ .... });
This approach can be used when you want to delegate the event..
Try this code. I have correct result view.
$('div').delegate('.someclass', 'click mouseover mouseout', function(e){ .... });
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