2

here is my code: basically what im trying to do is , when click event is triggered add a class using jquery to the current target. instead it is throwing undefined.

Template.section3.events({
        "click a.th":function(e,tmp){
            console.log(e.currentTarget);
            e.currentTarget.addClass("selected");
        }
    })
2
  • 4
    Try to use $(e.currentTarget).addClass("selected"); Commented Oct 2, 2014 at 17:43
  • 4
    e.currentTarget is the dom element, don't had the method addClass() Commented Oct 2, 2014 at 17:45

1 Answer 1

2

A better pattern would be to use the Session variable or a ReactiveVar to keep track of the selected item, and use a helper to set the class. That way, when Meteor re-renders that part of the page due to a change in data, the class will stay.

Sign up to request clarification or add additional context in comments.

3 Comments

If re-rendering is your only concern, using a reactive variable from the package reactive-var is more suitable than using Session.
I think using session would by a waste of cpu and memory usage. Am i wrong?
When Meteor updates the view to reflect the new state, it will only change the single class attribute just like the JQuery code above. Using Session to set the class name will not result in the whole template re-rendering.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.