Jonas
Jonas

Reputation: 477

.not selector with multiple variables

Is there a way to use multiple variables inside a .not() selector in jQuery?

e.g.

var target = $('.custom-element') // This must be in a variable
$('.element').not(this, target).toggleClass('visible');

Upvotes: 0

Views: 57

Answers (2)

omikes
omikes

Reputation: 8513

You might also try this, for simplicity's sake. CSS rules allow for comma separated selectors:

var target = $('.custom-element') // This must be in a variable
$('.element, .custom-element').not(this).toggleClass('visible');

Upvotes: 0

Satpal
Satpal

Reputation: 133403

You can't pass multiple parameters to .not(). However you can chain them

$('.element').not(target).not(this).toggleClass('visible');

You can use .add() to add the element this to existing group then it can used.

var target = $('.custom-element') ;
$('.element').not(target.add(this)).toggleClass('visible');

Upvotes: 1

Related Questions