Robert Granlund
asked on
JQuery Syntax
I am trying to grab the Dta Value from a specific select option:
the data is data-damage
What am I doing wrong?
<script>
var usage_sel = $('select[name="item_options[usage]"]').attr('data-damage');
var usage_var = usage_sel.data('damage');
if ( usage_var == null ) {
usage = 1;
} else if ( usage_var == undefined ) {
usage = 1;
} else {
usage = usage_var;
}
alert(usage);
</script>
The select name is item_options[usage]the data is data-damage
What am I doing wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I had to do the following: var usage_sel = $('select[name="item_optio ns[usage]" ]').find(' :selected' ).data('da mage');
ASKER