Reputation: 6107
In the above example the console logs a value of 1 which is the currently selected option. How can you log the <select>
tag's value of 2?
$(document).ready(function() {
console.log($('.mySelect').val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select class="mySelect" value="2">
<option value="1" selected>Choice 1</option>
<option value="2">Choice 2</option>
<option value="3">Choice 3</option>
</select>
Upvotes: 1
Views: 58
Reputation: 645
This would work for you .
console.log( $('.mySelect[value=2]').val() );
Upvotes: -1
Reputation: 1613
This is not valid HTML syntax.
Use data attributes like data-someattr
for values you want to pass.
Upvotes: 8