Reputation: 11295
I have initializing select2 like:
$('select').select2();
but now I have some select
boxes, that not need select2
, how I can add selector to select2
, that will skipped and, select2
will not initialize select2
for that select box ?
How I cant skip:
<select class='skip-me'></select>
Upvotes: 2
Views: 1213
Reputation: 11
You could try to do a loop searching for the selects and skiping the desired class selects. Something like this:
applySelectFormat();
function applySelectFormat(){
$('select').each(function(){
var e = $(this);
if(!e.hasClass('skip-me')) e.select2();
}
}
I think it's a solutions but it's not the best. You may have to test it if it takes more time to load the page...
Upvotes: 1
Reputation: 128786
Use the :not
selector:
$('select:not(.skip-me)').select2();
Description: Selects all elements that do not match the given selector.
Upvotes: 3