Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Instead of selecting all <code>&lt;select&gt;</code> elements, change your selector:</p> <pre><code>$("select.frm_ddl_notOk").each(function () { }); </code></pre> <p>This uses the <strong>class</strong> selector ( <code>.</code> ) - <a href="http://api.jquery.com/class-selector/" rel="nofollow">http://api.jquery.com/class-selector/</a> . It will only return elements with the specific class. So in your case, it will look for all <code>&lt;select&gt;</code> elements, then filter them based on whether they have the class "frm_ddl_notOk" or not.</p> <p>But more readable is:</p> <pre><code>$("select").filter(".frm_ddl_notOk").each(function () { }); </code></pre> <p>That is all if you are targeting a <code>&lt;select&gt;</code> element with the specific class (which is what your question seems to explain). But in your code, you seem to be looking at the <code>&lt;option&gt;</code> elements (specifically the selected one) to see if they have the class (using jQuery's hasClass - <a href="http://api.jquery.com/hasClass/" rel="nofollow">http://api.jquery.com/hasClass/</a> ). If so, you could try something like this:</p> <pre><code>$("select").each(function () { var $this = $(this); if ($this.find("option").filter(":selected").hasClass('frm_ddl_notOk')) { alert('bunter?'); } }); </code></pre> <p>This will find the <em>selected</em> <code>&lt;option&gt;</code> element for <strong>every</strong> <code>&lt;select&gt;</code> element and if it has the class you're looking at, it will alert.</p> <p>That uses the <code>:selected</code> selector - <a href="http://api.jquery.com/selected-selector/" rel="nofollow">http://api.jquery.com/selected-selector/</a></p> <p>So I guess my point is if you want to get the selected option, use:</p> <pre><code>$("select").find("option").filter(":selected") </code></pre> <p>If you want to set the selected option, use:</p> <pre><code>$("select").find("option").eq(YOUR INDEX).prop("selected", true); </code></pre> <p><a href="http://api.jquery.com/eq/" rel="nofollow">http://api.jquery.com/eq/</a></p> <p><a href="http://api.jquery.com/prop/" rel="nofollow">http://api.jquery.com/prop/</a></p> <p>And finally, if you don't need to operate on the specific <code>&lt;select&gt;</code> elements, just use this:</p> <pre><code>$("select").find("option").filter(":selected").filter(".frm_ddl_notOk").each(function () { // The &lt;option&gt;s that have the "frm_ddl_notOk" class }); </code></pre> <p>In this one, it finds all <code>&lt;select&gt;</code> elements, looks at their <code>&lt;option&gt;</code> children, only looks at the <em>selected</em> ones, and only with the class "frm_ddl_notOk".</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.
    1. VO
      singulars
      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