Home > other >  How to check value of div property in react
How to check value of div property in react

Time:03-25

I have a line in my component like so...

    <div className="progress" mx-auto data-value={100 - (100 * session.timeRemaining) / (session.label === "Focusing" ? focusDuration * 60: breakDuration * 60)}>

I want to do something like this...

    <div className="progress" mx-auto data-value={100 - (100 * session.timeRemaining) / (session.label === "Focusing" ? focusDuration * 60: breakDuration * 60)}>

 if (data-value > 0) {do stuff}

How do I monitor / check for the value of my divs data-value attribute?

CodePudding user response:

You can use getAttribute function.

<div className="progress" mx-auto data-value={100 - (100 * session.timeRemaining) / (session.label === "Focusing" ? focusDuration * 60: breakDuration * 60)}>
document.querySelector(".progress").getAttribute('value');
  • Related