Sauce
Sauce

Reputation: 662

How to return position of click event in Meteor.js

In a meteor.js app, I am trying to return the position of a click using jQuery's .position().

If I use event or this, I'm getting the error Uncaught TypeError: Cannot read property 'defaultView' of undefined.

If I use $( event.currentTarget ), it returns 0, since that defines the element that was clicked.

Template.myTemplate.events({
  // Doesn't work
  'click .target': function (event) {
    posY = $(event).position().top; // Undefined error
    console.log( posY ) 
  },

  // also doesn't work
  'click .target': function (event) {
    var $this = $( event.currentTarget );
    posY = $this.position().top; 
    console.log( posY ) // Returns 0
  }
});

In straight jQuery, I would do this:

$( '.target' ).click( function (e) { 
    var posY = $(this).position().top;
    console.log( posY )
});

My question is, how do I access the same this in Meteor?

Upvotes: 1

Views: 520

Answers (1)

Peppe L-G
Peppe L-G

Reputation: 8345

Use event.target instead of event.currentTarget.

Upvotes: 1

Related Questions