Given the following HTML:
<select id="addSelection">
<option value="Original Value">Original Value</option>
</select>
I would like to change the text value of the option tag when I click on a button.
Assuming that the button click can be done correctly...how can I change the text of the option tag using jQuery?
So, for example...I would like the option tag changed to this:
<option value="New Value">New Value</option>
I've tried using variations of the .val()
function but have not found a solution.
Thank you to all who reply!
The following simplified solution ...
<html>
<head>
<script type="text/javascript" src="jquery-1.5.2.min.js"></script>
<script type="text/javascript" >
function domread() {
$('#btn').click(function(){
$('#originalValue').attr('value', 'New Value').html('New Value');
});
}
</script>
</head>
<body onload="domread()">
<select id="addSelection">
<option id="originalValue" value="Original Value">Original Value</option>
<option value="Two Value">Value two</option>
<option value="Three Value">Value three</option>
</select>
<br/>
<input id="btn" type="button" value="Changes"></input>
</body>
</hmtl>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With