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?
Use the jQuery: selected selector in combination with val () method to find the selected option value in a drop-down list.
With jQuery, you can use the . val() method to get an array of the selected values on a multi-select dropdown list.
Method 1: Using the value property: The value of the selected element can be found by using the value property on the selected element that defines the list. This property returns a string representing the value attribute of the <option> element in the list. If no option is selected then nothing will be returned.
We can extract all the options in a dropdown in Selenium with the help of Select class which has the getOptions() method. This retrieves all the options on a Select tag and returns a list of web elements. This method does not accept any arguments.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With