JSFiddle - React, Tailwind, and code Playground
by nicosa
HTML
<body>
<div id='placeholder'>
<p>
<img src="http://i.imgur.com/yOadS1c.png" act='min' id="1" width="20" height="20" />
<input id="qty1" type="text" value="1">
<img src="http://i.imgur.com/98cvZnj.png" act='add' id="1" width="20" height="20" />
</p>
<p>
<img src="http://i.imgur.com/yOadS1c.png" act='min' id="2" width="20" height="20" />
<input id="qty2" type="text" value="1">
<img src="http://i.imgur.com/98cvZnj.png" act='add' id="2" width="20" height="20" />
</p>
</div>
</body>
JavaScript
$(function () {
$('#placeholder img').each(function(){
$(this).click(function(){
$action = $(this).attr('act');
$id = $(this).attr('id');
$val = parseInt($('#qty'+$id).val());
if($action == 'add'){
$val = $val + 1;
} else {
if($val > 0){
$val = $val - 1;
}
}
$('#qty'+$id).val($val);
});
});
});