I know one can get the value of the currently selected item like this:
var myListBoxItemText = $('#myListBox').val().toString();
But how do you change this value in the list box to something else?
I know one can get the value of the currently selected item like this:
var myListBoxItemText = $('#myListBox').val().toString();
But how do you change this value in the list box to something else?
$("#myListBox").val("This is the new value");
Although, by 'listbox', I assume you mean a
select
element. In which case you'll have to add the propertyselected
to one of the childoption
elements.Seeing your update in the comments, here's an updated answer. Just use the
:selected
selector to filter the options inside of yourselect
element to get the selected option.To change a
select
element's selected option'svalue
property:To change its display text:
JSFiddle
Here your_val denotes the
value
attribute of<option>
Or you can also use
or
DEMO
DEMO 2