To get a specific option by the
value
attribute, try this:
var html = '<option value="1">Official On</option><option value="2">Official Off</option><option value="3">Sick Leave</option><option value="4">Casual Leave</option><option value="5">Annual Leave</option>';
var options = $('<select>' + html + '</select>');
var found = options.find("[value='1']");
var foundText = found.text();
If you want to modify the value later, then do this:
found.text("Edited value here.");
After changing the value using the above way, you can get the new HTML using the
.html()
method on
options
:
var newHtml = options.html();
Then
newHtml
will be:
<option value="1">Edited value here.</option><option value="2">Official Off</option><option value="3">Sick Leave</option><option value="4">Casual Leave</option><option value="5">Annual Leave</option>