简体   繁体   English

使用Meteor.js单击时将类添加到特定元素

[英]Adding a class to a specific element on click with Meteor.js

I am using meteor.js and I am trying to add a class to specific button elements on click. 我正在使用meteor.js,并且试图在单击时向特定的按钮元素添加一个类。

I am getting the correct id for the elements with event.currentTarget.id, but the class I am adding is not being added (.selected). 我正在使用event.currentTarget.id获取元素的正确ID,但是没有添加(.selected)我添加的类。 What am I doing wrong? 我究竟做错了什么? Thank you! 谢谢!

Template.inquiry.events({
    'click .button': function(event){
        console.log(event.currentTarget.id)

        var report=event.currentTarget.id

        $(report).addClass('selected');

    }
});

jQuery expects a string such as #my-item when looking up by id. jQuery通过id查找时,需要一个字符串,例如#my-item

You probably need to do: 您可能需要做:

$("#" + report).addClass("selected");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM