jQuery - remove select option based on text not value

gavinlee發表於2016-04-20

you can use to filter based on text content of an element, but note that it will return partial matches.
So :contains('Vaillant 835')will return :contains('Vaillant 835') and :contains('Vaillant 8356')

jQuery("#select_Boiler option:contains('Vaillant 835')").remove();

If you want to filter for equal you need to do a manual filter like

jQuery("#select_Boiler option").filter(function()
{     return $.trim($(this).text()) == 'Vaillant 835' }).remove();

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/310974/viewspace-2084463/,如需轉載,請註明出處,否則將追究法律責任。

相關文章