3

This event is attached to a set of elements:

var elems = $(this).filter(function(){
  ...
});

How can I trigger a change event on these elements within a change event handler, but ignore the current element?

elems.bind('change input', function(){

  // do some stuff...

  // then trigger change, but not on "this", to avoid the recursion issue
  elems.change(); 

});

Basically I want ot ignore this from elems, but only in my "manual" change()-call above...

0

3 Answers 3

3
var elems = $(this).filter(function(){
  ...
});

elems.bind('change input', function(){


  // then trigger change, but not on "this", to avoid the recursion issue
  elems.not(this).change(); 

});

Though I must say, this scenario looks like a poor design issue.
When element get changed it sets a change event callback to some elements including him self... sound awkward and that recursion is just a symptom to other bigger problem...

It probably can be done in a a lot cleaner way then this.

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

Comments

3

Try this:

elems.not(this).change(); 

1 Comment

but I want to keep that event on all elements, I just don't want to be included when I trigger change manually
2

You can just filter out the current element:

elems.not(this).trigger('change'); // or just .change()

Comments

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.