I have the below code in my dropdown list:
<select id="state_code" name="account[state_code]">
<option value="">Select State</option>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="AE">Armed Forces</option>
<option value="AA">Armed Forces</option>
<option value="AP">Armed Forces</option>
<option value="AS">translation missing: en.world.us.as.name</option>
<option value="DC">translation missing: en.world.us.dc.name</option>
<option value="GU">translation missing: en.world.us.gu.name</option>
<option value="MP">translation missing: en.world.us.mp.name</option>
<option value="PR">translation missing: en.world.us.pr.name</option>
<option value="UM">translation missing: en.world.us.um.name</option>
<option value="VI">translation missing: en.world.us.vi.name</option>
</select>
I want hide all options whose text starts with translation missing: en.world.us
. I have tried the below, but its not working.
var ab = "translation missing: en.world"
$('#state_code').find('option[text^="' + ab + '"]').hide();
Please help me out. Thanks in advance.
The text of an element is not an attribute, so the attribute selector will not work in thise case, as you've discovered. Instead you can use a combination of a regular expression and the filter()
function to achieve this:
$('#state_code option').filter(function() {
return /^translation missing:/i.test($(this).text());
}).hide();
I want to hide now both translation missing: en.world.us and Armed Forces
For this you can use the 'or' character in regex: |
. What you tried won't work as the logic flow is flawed due to two return
statements. Try this:
$('#state_code option').filter(function() {
return /^translation missing:|armed forces/i.test($(this).text());
}).hide();
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments