Reputation: 29767
I have trying to add a class to parent div of my link like this:
$(document).ready(function() {
$(".food-result").on("click", "a", function (event) {
event.preventDefault();
$(this).parent().parent().addclass('active');
return false;
});
I get the error:
Uncaught TypeError: undefined is not a function
What am I doing wrong?
Upvotes: 0
Views: 86
Reputation: 1036
it looks like you are trying to get the parent of the parent which might not exist would this work
$(document).ready(function() {
$(".food-result").on("click", "a", function (event) {
event.preventDefault();
$(this).parent().addClass('active');
return false;
});
Upvotes: 0
Reputation: 2995
try this:
jQuery(document).ready(function($) {
$(".food-result").click(function (event) {
event.preventDefault();
$(this).parent().parent().addClass('active');
return false; // I am not sure if this is needed
});
});
Upvotes: 0