RBLtech87
RBLtech87

Reputation: 41

How do I ask jQuery to look at the value of multiple ID's

This is somewhat of a continuation of an earlier question. I have figured out how to use a selector to point to a specific ID and look for a value="", and then fill that with a red background... i.e. -

$('[id^="f04"][value=""]').css('background-color', 'red')

What I need to do now is build on this so it looks at f04, f05, and f06 for value=""... Any ideas on how to write that? I've tried several different ways to no avail.

Upvotes: 3

Views: 86

Answers (3)

ErikE
ErikE

Reputation: 50201

You use exactly what you would use with a CSS selector: commas:

$('#f04, #f05, #f06').filter('[value=""]').css('background-color', 'red');​​​​​​​​​​​

or the more awkward:

$('#f04:[value=""], #f05:[value=""], #f06:[value=""]')
   .css('background-color', 'red');​​​​​​​​​​​

See this in a fiddle.

Upvotes: 2

Tats_innit
Tats_innit

Reputation: 34107

To get all the elements starting with "f0" you should use:

$("[id^=f0]")

To get those that end with "f0"

$("[id$=f0]")

In your case something like this :)

$('[id^="f0"][value=""]').css('background-color', 'red')

See also the JQuery documentation

Upvotes: 2

Explosion Pills
Explosion Pills

Reputation: 191729

Very easy .. just change f04 to f0 in that selector. The ^= operator just means "begins with."

If it goes up to 10 or higher then I guses just ^=f will have to do.

Upvotes: 5

Related Questions