I have got:
$('.class1').click(function(){ //do
things on $(this) element })
and
$('.class2').click(function(){
//do things on $(this) element
})
things to do in each of that is the same, but when I did:
$('.class2').click(function(){
$('.class1').click();
})
... it was disaster, that actived开发者_Go百科 each element with class1
.
Is there any similar solution to above one?
Try this:
$('.class1, .class2').click(function(){
//do things on $(this) element
}) ;
$(".class1,.class2").click(function(){ });
Using the multiple selector is the best way here. However in some situations, you have to bind the handlers dynamically. Use named functions then:
function handler() {
// something
}
$('.class1').click(handler);
$('.class2').click(handler);
精彩评论