I am trying to keep my code consistent as I’m using jQuery for my project, however, I’m a bit confused about the each()
method of jQuery.
let cells=$(".cell").toArray();
my Vanilla JS code is here:
cells.forEach(function(cell,index){
cell.addEventListener('click',function(){
console.log(cell,index);
})
})
my jQuery is here:
cells.each(function(index,cell){
cell.click(function(){
console.log(cell,index);
})
})
I know the code is wrong, as the console shows Uncaught TypeError: cells.each is not a function
but I checked the jQuery Document, it says the each
method is the forEach
method in JS, I am really confused now.