Inside THIS jsFiddle I have 2 buttons, each with a custom data-direction attribute:
<div class="btn-group" id="controls">
<button type="button" class="btn btn-primary btn-sm" data-direction="left">Prev</button>
<button type="button" class="btn btn-primary btn-sm" data-direction="right">Next</button>
</div>
I am trying to console log the direction attribute upon clicking the buttons:
var updateCounter = function(){
var direction = $(this).data("direction")
if(direction === "left") {
counter--;
} else {
counter++;
}
console.log(direction);
}
But what I get is undefined
. Why?