Jessica
Jessica

Reputation: 3769

How can I exclude a class from my jQuery selector?

I have the following code:

$(":input[type='text']").wijtextbox();

What I would like is for the wijtextbox() NOT to be applied if the class of my textbox is native. Is there a way I can somehow exclude this by adding to the above selector?

Make this a wijtextbox:

<textarea class="wijmo-wijtextbox ui-widget ui-state-default ui-corner-all valid" >xx</textarea>

Don't make this a wijtextbox:

<textarea class="native wijmo-wijtextbox ui-widget ui-state-default ui-corner-all valid" >xx</textarea>

Upvotes: 9

Views: 9672

Answers (3)

Purag
Purag

Reputation: 17061

This:

$("input[type='text']").not(".native").wijtextbox();

or this:

$("input[type='text']:not('.native')").wijtextbox();

should do the trick. There's also a shortcut for selecting an input whose type is text:

$("input:text").not(".native").wijtextbox();

More on not() here.

EDIT: Since it appears you need to select a textarea, try the following:

$("textarea").not(".native").wijtextbox();

Upvotes: 14

ShankarSangoli
ShankarSangoli

Reputation: 69905

Try this.

$(":input:not(.native)").wijtextbox();

Since you selecting textarea you can even use this

$("textarea:not(.native)").wijtextbox();

:not(selector) - Selects all elements that do not match the given selector.

Upvotes: 4

seeming.amusing
seeming.amusing

Reputation: 1179

You can use jQuery's .not() selector, as documented here: http://api.jquery.com/not/

How you would use it would really depend on what specifically you're trying to find though.

Upvotes: 2

Related Questions