Reputation: 68670
I want to select the first element that does not have a class .disabled
.
I tried these without success:
$('.selected:first:not(".disabled")').addClass('first');
and
$('.selected:first').not(".disabled").addClass('first');
Upvotes: 0
Views: 87
Reputation: 8171
Your code:
$('.selected:first:not(".disabled")').addClass('first');
this code selects the first element with selected
class and than check is the the selected element not have disabled
class.
Answer :-
First you need to select the elements which not have css class disabled
.
Using:
$('.selected:not(.disabled)');
And after that select the first element into the matched element;
$('.selected:not(.disabled)').first();
Try this:
$('.selected:not(.disabled)').first().addClass('first');
Upvotes: 1
Reputation: 2247
You have to get all the element with class 'selected' but without class 'disabled' then get the first of them.
$('.selected:not(.disabled)').first().addClass('disabled');
or
$('.selected:not(.disabled):first').addClass('disabled');
Fiddle: http://jsfiddle.net/5LuXD/1/
Upvotes: 5