jQuery Mobile wraps select
with a div with class ui-select
. You need to use .closest()
to target that div and hide/show it.
Demo: Using .hide()
/ .show()
.
Demo: Using custom class and .toggleClass()
- Recommended.
$("#searchuniversitycampus").closest('div.ui-select').hide();
Explanation
.closest(): It begins with the current element, and travels up the DOM tree until it finds a match for the supplied selector. The returned jQuery object contains zero or one element for each element in the original set, in document order.
.parents(): It begins with the parent element, and travels up the DOM tree to the document's root element, adding each ancestor element to a temporary collection; it then filters that collection based on a selector if one is supplied. The returned jQuery object contains zero or more elements for each element in the original set, in reverse document order.
Recommendation
For jQuery Mobile, It is recommended to add/remove custom classes rather than using inline styles. Using .hide()
/.show()
adds style attribute to the element display: none;
/display: block;
which may cause conflict with elements that have display: block;
in jQuery Mobile CSS.
In light of the above, instead of using .hide()
/.show()
, make a custom class:
.hide {
display: none !important;
}
and use it with .toggleClass()
or .addClass()
/.removeClass()
.