Select elements with class except one with specifi

2019-02-18 01:36发布

问题:

$('.ui-widget-content').css('border','none');
    $('#helpDialog .ui-widget-content').addClass('HelpDialogBorder');

I am doing like this to remove border. But, there is an element where I want to keep border.

Is there any way in first line itself to select all elements with class "ui-widget-content" but except one with id "helpDialog"?

回答1:

Sure, use :not():

$('.ui-widget-content:not(#helpDialog)').css('border', 0);


回答2:

Try this (also see my jsfiddle):

$('.ui-widget-content').not('#helpDialog').css('border','none');


回答3:

You can try this $('.ui-widget-content').not('#id')