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");
3
  • In your code itself i see that radior is first triggered and then onchangeofvalidationandsubquestion is triggered . You can check it jsfiddle.net/h5zJe Commented Jul 16, 2014 at 13:56
  • Thanks Roshan. In my page onchangeofvalidationandsubquestion is triggered first. But jsfiddle example radior is triggered first. ı am confused Commented Jul 16, 2014 at 14:11
  • In that case I think answer by Pondwater is the best. Commented Jul 16, 2014 at 14:17

1 Answer 1

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/

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

2 Comments

Thanks for the answer.I will try it.But Is there another way to handle it without not triggering event in the radior event?
This is probably the easiest and simplest way to guarantee event order with jQuery, see: stackoverflow.com/a/290294/785259

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.