Reputation: 81
This code will output the right class name but not the right data-validamount. it will only output : undefined.
$(".prod_amount_add").click(function(){
var rowAmount = 0;
var datavalid = $(this).attr('data-validamount');
console.log(datavalid);
console.log($(this).attr('class'));
});
<div class="prod_amount_add">
<img src="icons/add.png" width="16" height="16"
alt="Plus 1" data-validamount="1">
</div>
Upvotes: 0
Views: 79
Reputation: 5962
you need to find your img attr after click on div . as it is part of img not of div
$(".prod_amount_add").click(function(){
var rowAmount = 0;
var datavalid = $(this).find('img').attr('data-validamount');
console.log(datavalid);
console.log($(this).attr('class'));
});
Upvotes: 0
Reputation: 4751
The attribute is on your img
, not your .prod_amount_add
div, so you'd do $(this).find('img').attr('data-validamount');
Upvotes: 2