First of all: If you want to get the selected item in a meteor, you do not need jQuery. Just take the change event and get the data using JavaScript:
Template.show.events({ 'change #options': function (event) { var currentTarget = event.currentTarget; console.log('Selected Value: ' + currentTarget.options[currentTarget.selectedIndex].value); console.log('Selected data: ' + currentTarget.options[currentTarget.selectedIndex].dataset.id); } });
Second: To get the item data, you should always use event.currentTarget.dataset .
Using event.target.dataset , you will get the wrong data set in some cases.
eg:.
<template name="show"> <div class="target" data-id="1"> <h1>Category with id 1</h1> <div class="anotherTarget" data-id="15"> Object with id 15 </div> </div> </template> if (Meteor.isClient) { Template.show.events({ 'click .target': function (event) { var currentTarget = event.currentTarget.dataset; var target = event.target.dataset; console.log(`CurrentTarget: $(currentTarget.id)`); console.log(`Target: $(target.id)`); } }); }
event.target gives you the element you clicked on. In some cases, this may be a child of the element on which the handler is installed.
event.currentTarget always returns the element on which you set the handler.
Here is an example: http://currenttarget.meteor.com/
Daniel Budick
source share