zkanoca
zkanoca

Reputation: 9918

All elements with attribute class not containing "disabled"

I have a few buttons which are generated programatically:

<button id="btn_b1" type="button" class="btn btn_default disabled">Disabled Button</button>
<button id="btn_b2" type="button" class="btn btn_default">Button</button>

The following code

$("button[id^='btn_b'][class~='disabled']") 

selects <button> elements with an id attribute value containing the string btn_b and class attribute value contains disabled.

What I want to select are

<button> elements with an id attribute value containing the string btn_b and class attribute value does not contain disabled.

Upvotes: 0

Views: 112

Answers (3)

Kiran
Kiran

Reputation: 20313

Use .not() method:

$("button[id^='btn_b']").not('.disabled');

Upvotes: 2

sudhansu63
sudhansu63

Reputation: 6180

Try this.

$("button[id^='btn_b']:not(.disabled)")

Upvotes: 1

Itay
Itay

Reputation: 16777

Use the :not() pseudo class.

$("button[id^='btn_b']:not(.disabled)") 

Upvotes: 1

Related Questions