user1927865
user1927865

Reputation: 135

jQuery find all elements start with specific id but not with another specific id

I have the following html:

input id="abc_0_1"
input id="rub_0_1"
input id="rub_0_2"
input id="rub_1_1"
input id="rub_1_2"
input id="rub_2_1"
input id="rub_2_1"
input id="abc_4_5"

Using jQuery I want to select only the inputs that start with 'rub_' but do not start with 'rub_0'

How can I do it, assuming I have much more inputs with similar ids?

Thanks,

Avi

Upvotes: 0

Views: 264

Answers (3)

Milind Anantwar
Milind Anantwar

Reputation: 82251

use:

$('input[id^="rub_"]:not([id^="rub_0"]')

Upvotes: 0

Bhojendra Rauniyar
Bhojendra Rauniyar

Reputation: 85573

Use like this:

$('[id^="rub_"]:not('[id^="rub_0"]')

Or, like this:

$('[id^="rub_"]).filter(function(){
   return $(this).not('[id^="rub_0"]);
})

more details on attribute selector

Upvotes: 0

Arun P Johny
Arun P Johny

Reputation: 388416

You can use attribute starts with selector and not selector

var $els = $('input[id^="rub_"]:not([id^="rub_0"])')

Upvotes: 5

Related Questions