Reputation: 20004
Using the .change()
event I want to store the value of an attribute of the currently selected option. Please help me finish the below code.
$("#someid").change(function() {
var myNumber;
});
Upvotes: 2
Views: 247
Reputation: 322492
If you want need it outside the handler, you'll need to declare the variable outside.
var myNumber;
$("#someid").change(function() {
myNumber = this.options[ this.selectedIndex ].getAttribute('myAttr');
// or
myNumber = $(this).find('option:selected').attr('myAttr');
});
If you only need it inside, then declare the variable inside.
Upvotes: 4