Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery/javascript to read select box css/class
    primarykey
    data
    text
    <p>I have inherited some code that sets the css of a select box depending on the option that has been selected. There are many select boxes on the page and my goal is just to get select boxes that have the "failure" css style.</p> <p>I think that I have got relatively close but I just can't get it to work for me. Relatively close means that I can get the css class displayed in a JavaScript alert box but when I try to use that text value in an if statement nothing happens. That code is below.</p> <p>Any pointers gratefully received.</p> <pre><code>$("select").each(function () { alert(this.options.item(this.options.selectedIndex).className); if (this.options.item(this.options.selectedIndex).className == 'frm_ddl_notOk') { alert('bunter?'); } }); </code></pre> <p>EDIT 20 hours later...</p> <p>I am an idiot. I mispelled the class that I was looking for. Should be "form_ddl_notOk". It is distinctly depressing how long it took me to notice. Especially after I used a prompt box so I could cut and paste the class name back into my code (and then didn't do it!).</p> <p>The imperfect code that I posted with my question worked when I used the correct class name.</p> <p>Here's some background to my question and responses to others questions and comments:</p> <p>When I find an element in "failure" I will look for a sibling element called "comments" and make it obligatory that "comments" be filled. I cannot base the selection on the option text I must base this on the class and/or bgcolor. The style is applied to the select element and the option element. I was using more general selectors just to try to figure stuff out.</p> <p>Thanks for your replies. Not sure whether I should mark any of them as the "answer". The universe would probably carry on without much amiss if this Q was deleted.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload