MAX POWER
MAX POWER

Reputation: 5438

jQuery - multiple event handlers - specify order

I have two checkbox change events as follows:

1) This targets a specific checkbox:

$('#category').on('change', '#cars input[type=checkbox]', function(){
     //
});

2) And this targets all checkboxes:

$('#category').on('change', 'input[type=checkbox]', function(){
     //
});

The second event seems to be firing before the first one, but I would like the opposite instead.

How can I specify the order?

Upvotes: 3

Views: 56

Answers (1)

dkasipovic
dkasipovic

Reputation: 6120

If applicable, you should try something like this instead:

$('#category').on('change', 'input[type=checkbox]', function(){
  if ($(this).parent().attr('id')=='cars') {
    //do for cars
  }
  //do for everything
});

Upvotes: 4

Related Questions