0

In place of check boxes I am using 16px text boxes with an X that is placed/removed on clicking using js (this allows customization of size of the box etc which is more difficult with check boxes). On my form some of the text boxes will highlight with a yellow background if indicated. I want to be able to "check all suggested text boxes" with one click.

function checkBox(){
$("input[type=text]").val("X");
 } 

This code will put X's in ALL the text boxes (it works).

How do I select out only the text boxes with background color yellow (the other text boxes are either background color white or blue)? Something like:

 function checkBox(){
$("input[type=text:style=background,yellow]").val("X");
 } 

The above code does not trigger a console error...but simply does nothing.

  • Adjusting check box sizing is possible (at least in newer browsers): http://stackoverflow.com/a/10415275/1503476 – Horen Apr 11 '14 at 04:35

1 Answers1

0

You should really be using CSS classes for something like this.

CSS:

.yellow{
   background: yellow;
}

jQuery:

$("input[type=text].yellow").val("X")

Your query $("input[type=text:style=background,yellow]").val("X"); does not work because you can only query for html and not css attributes with jQuery.

Horen
  • 11,184
  • 11
  • 71
  • 113
  • I am using jquery to "overlay" another form. The form is very amateur. – user3522054 Apr 11 '14 at 13:01
  • I am using jquery to "overlay" another form. The form is very amateur.This is the answer I needed, problem is the "check box" has styling = for each box background:transparent or background:lightblue; and this trumps the class. What I might do is when setting the background yellow, I could also add a class "check" and then jquery could use this class as the filter. – user3522054 Apr 11 '14 at 13:08
  • Sorry to answer my own questions. Found !important for the style and it now works! (background: yellow !important;) Probably sloppy but does the job. – user3522054 Apr 11 '14 at 14:21