Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

JQuery Syntax

I am trying to grab the Dta Value from a specific select option:
<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>

Open in new window

The select name is item_options[usage]
the data is data-damage

What am I doing wrong?
ASKER CERTIFIED SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Robert Granlund

ASKER

When I do this: var usage_sel = $('select[name="item_options[usage]"]').data('damage');   I have it to alert on change and I get undefined.  Do I need to add more to it to get the DATA value from the selected option?
I had to do the following: var usage_sel = $('select[name="item_options[usage]"]').find(':selected').data('damage');