Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery hide selectMenu?

I'm using jQuery's selectMenu on a select tag like this.

$('#ddlReport').selectmenu()

in certain cases I want to hide it, and I can't figure out how.

this doesn't work:

$('#ddlReport').selectmenu().hide();

neither does this

$('#ddlReport').hide();

anyone?

like image 528
Igal Avatar asked May 02 '12 19:05

Igal


4 Answers

After losing a few hours trying to figure this out. I finally wrapped the thing in a <div> and just show/hide on the div. Certainly far from elegant but it keeps me out of the jq mobile innards.

like image 67
Nick Van Brunt Avatar answered Oct 28 '22 16:10

Nick Van Brunt


With newer versions of jQueryUI (I'm working with version 1.11.4), simply use the "widget" attribute:

$("#element").selectmenu( "widget" ).hide();
like image 20
Itaypk Avatar answered Oct 28 '22 17:10

Itaypk


Looking at the demos here and here, it seems selectmenu works by appending a

<span class="ui-selectmenu-button">
or (probably different selectmenu versions?)
<a ... class="ui-selectmenu ...">

after the original select, containing the artificial select.

You could try accessing that using

$('#ddlReport').next('.ui-selectmenu .ui-selectmenu-button').hide();

Though it sounds like it may use other classes (instead of -button). This is also a kind of hackish workaround and I'm sure the plugin contains some way intended to let you access the newly appended menu.

Edit: Looking through the code in the second demo, it doesn't seem like there is any preprogrammed way to access the new select in that version at least.

like image 3
Armatus Avatar answered Oct 28 '22 17:10

Armatus


 $("#ddlReport").parent().hide();

works for me.

like image 3
Chris M Avatar answered Oct 28 '22 18:10

Chris M