Reputation: 2103
How to run through all textareas, excluding one whose id I have?
$("textarea").each(function (i, v) {
// i could use an "if" inside here, but would rather adjust the selector
});
I have tried using :not($('#mySpecialTextarea'))
, but could not get that to work.
Upvotes: 1
Views: 230
Reputation: 23816
Use jquery .not()
$("textarea").not('#mySpecialTextarea').each(function (i, v) {
// your code
});
You can also use :not()
$("textarea:not('#mySpecialTextarea')").each(function (i, v) {
// your code
});
The
.not()
method will end up providing you with more readable selections than pushing complex selectors or variables into a:not()
selector filter. In most cases,.not()
is a better choice.
Upvotes: 4