I have an object:
var obj = { id: $('#f_view') };
I have a function:
function switchFrom(trigger) {
trigger.id.click(function() {
this.id.toggleClass('class');
});
};
When i run the function:
switchFrom(obj);
I get :
undefined is not a function (evaluating'this.id.toggleClass('class')')
When I refer to the element explicitly, the function works.
$('#f_view').toggleClass('class');
What Am i doing wrong? Thank you for your time.
idis a pretty bad variable name in your case. Should be something like$eletrigger.id.toggleClass('class');is what you wanted to do. The answer below is probably better thoughthisreference.