MeteorJS: How to get clicked element

倖福魔咒の 提交于 2019-12-31 02:13:24

问题


I'm trying to get the clicked element so that I can add class. Does Meteor provides any way to get the current element like jQuery $ (this)

Template.retraining.events({
    'click .myclass': function (event) {
        //Get the clicked element like $(this) in jQuery
        $().addClass('existing-col');
    }
});

回答1:


To get the element on which the event occurred, use event object.

event.target

As you've jQuery included, you can wrap the element in jQuery to use jQuery methods on it.

$(event.target)

You can see this in Meteor Tutorial




回答2:


From this you can get textbox value with one button click event.

Try this:

Template.retraining.events({
'click .myclass':function(e,t){
 var val = t.find(".classname").value;
}


来源:https://stackoverflow.com/questions/35194509/meteorjs-how-to-get-clicked-element

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!