1

I checked other's questions and still can't make this code work. I get undefined

$('a').on('click', () => {
  console.log($(this).attr('data-target'));
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<a href="#er" data-target="SDfdf">Click me</a>
Alexey Tseitlin
  • 1,031
  • 4
  • 14
  • 33

1 Answers1

-1

$('a').on('click', (e) => {
  console.log(e.target.dataset.target)
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<a href="#er" data-target="SDfdf">Click me</a>
ksav
  • 20,015
  • 6
  • 46
  • 66