I want to hide a select with the chosen-select class applied if it has no elements except it doesn't work.
Ive tried
$("#Category2").hide();
and then removing the chosen-select class prior to hide attempt:
$("#Category2").remove("chosen-select");
$("#Category2").hide();
but neither approach works. If I don't do:
$(".chosen-select").chosen();
then the select will hide. Also no errors in Chrome Developer tools console.
Is this a known issue? Is there a "trick" to doing this?
Chosen creates additional elements - try $("#Category2_chosen").hide();
. See it work: http://jsfiddle.net/lhoeppner/9UB23/
Edit for further explanation:
Try using your browser's development tools to inspect the DOM elements (usually right-click on the element, then "Inspect element" or similar).
You'll see that once you call $(element).chosen()
on a DOM element, the following things happen:
style="display: none;"
) chosen-container
and an id which is derived from the element's id (in this case by appending "_chosen" to it) The underscore doesn't have any special meaning, it's simply chosen's way of creating another unique id. It could just as append "-chosen" or "_mycustomsuffix".
$("select#chosen-select").hide()
应该做的伎俩。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.