4

just like the example: http://jsfiddle.net/nicaia/6cHxR/

the js code:

$('#checkbox_id').bind('change',function({
    alert('change');
}).bind('click',function(event){
    alert('click');event.preventDefault();
});

in chrome click the checkbox will show this:

alert 'change' and alert 'click' and the checkbox will not be checked.(the checkbox is uncheck in first.)

and in firefox click the checkbox will show this: alert 'click' and the checkbox will not be checked.(the checkbox is uncheck in first.)

the change will not be triggered in firefox. i don't know why.somebody can tell me?

thanks.

4
  • 3
    I think it is because the checkbox loses focus after alert. Therefore 'change' event is not triggered api.jquery.com/change Commented Dec 23, 2011 at 10:31
  • but in chrome the change event will be triggered. Commented Dec 23, 2011 at 11:05
  • linkthis question and my question is a bit like. and thanks @Nicola Commented Dec 28, 2011 at 8:24
  • @Sergey You will find the same issue if you replace alert with console.log. Commented Jan 22, 2013 at 6:56

1 Answer 1

0

I think that chrome has a different behaviour from other browsers. I tried this code:

$('#checkbox_id').bind('change',function(){
    alert('change');
}).bind('click',function(event){
    alert('click');
});

(fiddle here: http://jsfiddle.net/6cHxR/8/) and Firefox execute the click handler before the change handler while IE and chrome execute the change handler before the click handler. I don't think that you can do a lot about that

Sign up to request clarification or add additional context in comments.

2 Comments

in the click function this code "event.preventDefault()" stop the change event execute in firefox,because the click handler is executed before the change handler.why the click handler will be executed before change handler in firefox?
@Bodil i think that firefox handles event differently from other browsers. I don't know if there is a specification for this and so every vendor makes his implementetion. to me it makes more sense that the click handler execute before the change handler, but that's my opinion

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.