0

I have multiple select-elements like this:

<li>
    <select>
        <option>select something</option>
        <option value="1">something</option>
        <option value="2">anything</option>
    </select>
</li>
<li>
    <select>
        <option>select something</option>
        <option value="1">something</option>
    </select>
</li>
<li>
    <select>
        <option>select something</option>
        <option value="1">something</option>
    </select>
</li>

Now I need to change the opacity to 0.5 for every select element which has a selected option after the page has loaded. I'm not quite sure if this can be done by pure CSS, so I tried to do that with JQuery:

$('select').each(function(select) {
    $('select option').each(function() {
        if($(this).is(':selected')) {
            select.css({ opacity: 0.5 });
        }
    });
});

But this is not correct as it doesn't work.

user3142695
  • 15,844
  • 47
  • 176
  • 332
  • Do you want to `disable` it or just change the opacity? – Tushar Nov 07 '15 at 07:06
  • Just change opacity, because I want to set the opacity back to 1 on a mouseover-event – user3142695 Nov 07 '15 at 07:09
  • this might work for you – Alok Kumar Mishra Nov 07 '15 at 07:29
  • a `select` element with options always has one option selected... what exactly are you trying to do – But those new buttons though.. Nov 07 '15 at 07:33
  • @billynoah I'm thinking of a selected option except the default one (=first option without value) – user3142695 Nov 07 '15 at 07:37
  • 1
    none of the options in your question have a value. please update your question and respective code to illustrate exactly what you are trying to achieve. – But those new buttons though.. Nov 07 '15 at 07:51
  • 1
    @billynoah I have updated the post. If 'select something' is selected the opacity should be 1. If anything else is selected it should be 0.5 – user3142695 Nov 07 '15 at 08:01
  • Possible duplicate of [Style – Asons Nov 07 '15 at 08:38