I'm trying to figure out how i can get data attritube and i have search some answer but it's all not working.
<div onClick={handlePropsClick}
title={'aaa'}
data-id={2}
>
<div className='value-text'>Hello</div>
</div>
const handlePropsClick = () => event => {
alert(event.target.getAttribute('data-id'));
};
But I get null and am expecting to get 2 So what's the best way to do this in react
from the suggestion of @Jaromanda X I try to debug and print the value of event.tartfer to console below is what I got
console.log(event.target)
output: <div class="value-text">Hello</div>
which is a child element then i do
console.log(event.target.parentNode)
output:
<div title="aaa" data-id="2">
<div class="value-text">Hello</div>
</div>
and then when i do console.log(event.target.parentNode.getAttribute)