1

I have a checkbox element that has two classes.And this classes click event ı do some stuff. onchangeofvalidationandsubquestion is always trigger first but i want to it to execute first "radior" click event than "onchangeofvalidationandsubquestion" event.Any ideas will be helpful

$(".radior").click(function (event) {

});

$(".onchangeofvalidationandsubquestion").click(function (event) {

});

 var $radio = $('<input  class="radiowidther" type="checkbox"  />').appendTo($div);
$radio.addClass("radior");
$radio.addClass("onchangeofvalidationandsubquestion");
Pramod
  • 2,828
  • 6
  • 31
  • 40
Polat Aydın
  • 87
  • 1
  • 11
  • In your code itself i see that radior is first triggered and then onchangeofvalidationandsubquestion is triggered . You can check it http://jsfiddle.net/h5zJe/ – Roshan Jul 16 '14 at 13:56
  • Thanks Roshan. In my page onchangeofvalidationandsubquestion is triggered first. But jsfiddle example radior is triggered first. ı am confused – Polat Aydın Jul 16 '14 at 14:11
  • In that case I think answer by Pondwater is the best. – Roshan Jul 16 '14 at 14:17

1 Answers1

1

You could always add your own custom event to be triggered after:

$(".radior").click(function (event) {
    $(".onchangeofvalidationandsubquestion").trigger('myCustomEvent');
});

$(".onchangeofvalidationandsubquestion").on('myCustomEvent', function (event) {

});

This way the click event is guaranteed to be processed first.

Here's a quick little jsfiddle for registering and triggering custom events with jQuery:

http://jsfiddle.net/85XqL/

kbirk
  • 3,906
  • 7
  • 48
  • 72
  • Thanks for the answer.I will try it.But Is there another way to handle it without not triggering event in the radior event? – Polat Aydın Jul 16 '14 at 13:49
  • This is probably the easiest and simplest way to guarantee event order with jQuery, see: http://stackoverflow.com/a/290294/785259 – kbirk Jul 16 '14 at 13:52