4

This meteor client code needs the width of the element for which the event happened but failed to get it. How can it be done? Thanks

Template.swipe.events({
  'mouseup .swipe': function(e) {
    utility.mouseUp(e);
  }
});

utility = (function () {

  return {
    mouseUp: (event) => {
      console.log(event.currentTarget.width);
    }
}());
Fred J.
  • 5,759
  • 10
  • 57
  • 106
  • 1
    DOM nodes don't have a `width` property. Did you mean [offsetWidth](https://developer.mozilla.org/en-US/docs/Web/API/CSS_Object_Model/Determining_the_dimensions_of_elements)? – John Dvorak Jul 25 '16 at 05:18
  • use .width() property. – Ronak Patel Jul 25 '16 at 05:22
  • @JanDvorak - offsetWidth wasn't the solution for me. However your link revealed the correct property I was searching for: scrollWidth. Just in case someone else has the same problem! – MerlinK Feb 14 '17 at 14:20

1 Answers1

5

Use the event.currentTarget.offsetWidth property instead of width.

David Robles
  • 86
  • 1
  • 8
  • "`target` = element that triggered event; `currentTarget` = element that listens to event" - source: https://stackoverflow.com/q/10086427/5113030 . Related: https://thisthat.dev/current-target-vs-target – Artfaith Dec 27 '22 at 05:04