3

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.

2
  • @amon Incorrect. $('#f04[value=""] #f05[value=""] #f06[value=""]') will return no elements, first because the syntax is wrong (missing a colon before the square brackets) but also because I doubt each next one is a descendant of the previous. Commented Jul 31, 2012 at 23:48
  • @user1556164 Are there other elements in the page that have an id starting with f or f0? Commented Jul 31, 2012 at 23:49

3 Answers 3

5

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

1 Comment

there are f values ranging from f01-f09, however, I need only to select the values f03-f06 for the highlighting of value"" fields. This model will not accommodate.
2

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.

2 Comments

There are values #f01-#f09... what I need is for only F03, F04, F05, and F06 to highlight in red the blank fields.
@RBLtech87 How are they not working? I just retested that both methods work fine in the attached fiddle. Would you please check that and modify it per your situation, and post back with an updated fiddle if you cannot get it to work?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.