remove works but not hide?

2019-07-23 05:53发布

问题:

creating a filter for a select menu and having a few problems!

the first one is

$("#filterContentMenu option:contains(a)").hide();

doesn't work but

$("#filterContentMenu option:contains(a)").remove();

does.

Actually this only seem to be a problem in safari! Works in firefox?

回答1:

.hide() sets an element's display to none. You can't set an <option> to display: none, it won't work in all browsers. You can remove them and retain a reference to them, though:

var removed = $("#filterContentMenu option:contains(a)").remove();

// later that day...
removed.appendTo("#filterContentMenu");


回答2:

"Hiding" (setting to display: none) options isn't very well supported in several browsers. It is really better to delete and recreate them.



标签: jquery safari