Edit: Thanks for the help! using "console.log(this.getAttribute('data-x'));" fixed my problem
I'm working on a project where I want to have a grid of Div's each with a unique coordinate. I'm using data- tags to hold two coordinates and I want to console log the values when each div is clicked.
HTML:
<div class="cell" data-x="1" data-y="1"></div>
...and so on until
<div class="cell" data-x="12" data-y"12"></div>
JavaScript
var cell = document.querySelectorAll('.cell')
for (var i = 0; i < cell.length; i++){
cell[i].addEventListener('click',function(){
console.log(cell[i].getAttribute('data-x'));
});
};
This code is just trying to console log the data-x value for now, but its not working... Can anyone suggest a solution?