Reputation: 8141
I'm fairly new to Jquery, hence the noob questions......
Iv been trying to follow this to toggle a class on and off when a user clicks a link, iv got it now so that if the user clicks a link with lets say id="22" it will tick the tickbox with id="tick_22", what I'm trying to do now is add some user feedback so that the link changes colour when the tick box is ticked. I have tried to follow the example on the Jquery site http://api.jquery.com/toggleClass/ , but for some reason its not working ?. I'm not sure if I need to use (this.class) or just (this) ?.
$(document).on('click', '.selectlink', function () {
var myId = $('#check_' + this.id);
if ($(myId).is(':checked')) {
$(myId).prop('checked', false);
$(this).toggleclass( activeselectlink, addOrRemove );
}
else {$(myId).prop('checked', true);
$(this).toggleclass( activeselectlink, addOrRemove );
}
countChecked();
});
});
</script>
Upvotes: 0
Views: 3617
Reputation: 2763
First its .toggleClass()
not .toggleclass()
.
Second, the variable addOrRemove
has not been declared anywhere. It is supposed to be a variable of type boolean.
Upvotes: 0
Reputation: 74738
You can put the class to toggle in "class2toggle"
:
$(this).toggleClass("activeselectlink"); // this should work
Upvotes: 1
Reputation: 1652
case is wrong.
Check for it first :
.toggleClass instead of .toggleclass
Upvotes: 1
Reputation: 2192
check your case, Javascript/jQuery use Camel case..i.e. name it toggleClass and not toggleclass .. http://api.jquery.com/toggleClass/
Upvotes: 3