javascript - How can I hide an option of a select by it's text value? -
i have below code in 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 options text starts translation missing: en.world.us
. have tried below, not working.
var ab = "translation missing: en.world" $('#state_code').find('option[text^="' + ab + '"]').hide();
please me out. in advance.
the text of element not attribute, attribute selector not work in thise case, you've discovered. instead can use combination of regular expression , filter()
function achieve this:
$('#state_code option').filter(function() { return /^translation missing:/i.test($(this).text()); }).hide();
i want hide both translation missing: en.world.us , armed forces
for can use 'or' character in regex: |
. tried won't work logic flow flawed due 2 return
statements. try this:
$('#state_code option').filter(function() { return /^translation missing:|armed forces/i.test($(this).text()); }).hide();
Comments
Post a Comment