How do I select all the select boxes using a jQuery selector where value selected is "A1"?
Sample select box:
<select name="accesslevel">
<option value="A1">A1 Access</option>
<option value="A2">A2 Access</option>
</select>
I have to use the selector to do the following thing:
.parent().nextAll('td[id^="A1Access"]').show();
.parent().nextAll('td[id^="A2Access"]').hide();
Can anyone help?
As mentioned before, Prakash's solution is the closest, but it selects the option value rather than the select box itself. This can be fixed with the :has selector.
$('select:has(option[value="A1"]:selected)')
Try :
$('select option[value="A1"]:selected')
$('select').filter(
function(){
if($(this).val()=="A1")
return true;
else
return false;
}
)
you can add your function after this like
$('select').filter(
function(){
if($(this).val()=="A1")
return true;
else
return false;
}
).parent().nextAll('td[id^="A1Access"]').show();