New to ES6. Trying to grab data attribute of clicked link. HTML:
<ul class="home-news-slider-categories">
<li><a href="#" data-slide="1">Slide 1</a><li>
<li><a href="#" data-slide="2">Slide 2</a><li>
...
</ul>
In my JS, I've written a test function to grab the slide
data attribute on a given item when clicked:
$('.home-news-slider-categories > li > a').click((e) => {
console.log($(this).data('slide'));
e.preventDefault();
});
The event is being fired whenever I click a link, but the console is returning undefined
each time.
Am I using $(this) incorrectly?