0

If I am adding an event listener to an element that as a font size that isn't directly defined, what's the best way to increment that on click?

For example event.target.style.fontSize is equal to "" when trying to read it and increment it.

  cont.addEventListener('click', () => {
    let size = parseInt(event.target.style.fontSize.split("px")[0]) + 5;
    event.target.style.fontSize = fontSize.toString() + "px"

});

1 Answers1

0

Sounds like a job for window.getComputedStyle:

The computed style is the style actually used in displaying the element, after "stylings" from multiple sources have been applied. Style sources can include: internal style sheets, external style sheets, inherited styles and browser default styles.

Arash Motamedi
  • 9,284
  • 5
  • 34
  • 43