I have this div in my reactJS project:
<div
className="td-creator"
id="Creator"
tooltiptext="Melder"
onMouseOver={setToolTip}
onMouseOut={hideToolTip}
>
I am trying to get the value of tooltiptext by using getelementbyid.
I can succesfully store the div element in a variable name target and when I print it in the console it shows me this:
but when I try to use target.tooltiptext it returns undefined.
is there any way to acces the tooltiptext value in Javascript?
3
Answers
This is because tooltiptext is not a property of the HTMLDivElement.
Try
getAttribute
:Use
getAttribute
to get the value of that attribute:Most suitable way is to use data attributes
Here is an example from https://developer.mozilla.org/