Can jQuery each() be used to modify each item(option) in a select list? -
given select list:
<select id="my_list"> <option value="one">one</option> <option value="two">two</option> <option value="three">three</option> </select>
i'd jquery iterates on each of option items , changes disabled when condition of each() statement met.
i'm trying (just test):
$('#my_list').each(function(){ alert('test'); if($(this).val()=='two')){ $(this).css('background-color':'gray','padding':'10px'); } });
but alert never fires tell me iterating on values of option list.
the first problem you need #
in selector:
$('#my_list');
the second need select the option
elements, not select
:
$('#my_list option')
the third problem can't reliably style option
, select
elements anyway.
nb achieve code above putting value
check selector:
$('#my_list option[value="two"]').css(...);
Comments
Post a Comment