I have a very simple select box:
<select multiple="multiple" name="Condiments">
<option selected="selected">Mustard</option>
<option selected="selected">Ketchup</option>
</select>
and I'm using the jQuery UI MultiSelect Widget to make it a bit spiffier:
https://github.com/ehynds/jquery-ui-multiselect-widget
Specifically I'm trying to set one of the options dynamically when the widget is initialized. When I do this:
$("select").multiselect({
selectedText: function(numChecked, numTotal, checkedItems){
return "Foo";
}
});
it properly sets the selectedText option to "Foo" but when I do this:
$("select").multiselect({
selectedText: function(numChecked, numTotal, checkedItems){
return $(this).attr("name");
}
});
it think that $(this) is a span from somewhere else in the DOM.
If there were only one select on the page this would be fine, but with multiple i need a way to set this option for each. Is there an obvious way to get from $(this) to the current select element? or an obvious alternative to solving the same general problem?