You can use the :contains()
selector to find an element by its text content.
Assuming $(@el).find('.size > option')
finds the <option>
s:
$(@el).find('.size > option:contains(size1)').prop('selected', true);
سؤال
i have a dropdown list and want to set the default option by its text(not value), the drop down list is:
<select class="size">
<option value="0">size0</option>
<option value="1">size1</option>
<option value="2">size2</option>
</select>
i want to set the default value to size1, and i tried the following code but none of them works:
$(@el).find('.size>option').filter(=>$(this).text() == 'size1').prop('selected', true)
$(@el).find('.size>option[text="size1"]').attr('selected', true)
$(@el).find('.dimension_post option[text="size1"]').attr('selected', true)
thanks
المحلول
You can use the :contains()
selector to find an element by its text content.
Assuming $(@el).find('.size > option')
finds the <option>
s:
$(@el).find('.size > option:contains(size1)').prop('selected', true);