Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I get the value of a custom div variable in Javascript?

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:

console message

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

but when I try to use target.tooltiptext it returns undefined.
is there any way to acces the tooltiptext value in Javascript?

>Solution :

This is because tooltiptext is not a property of the HTMLDivElement.

Try getAttribute:

const toolTipText = target.getAttribute("tooltiptext");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading