Javascript 尝试在jQuery中将类添加到父类时出错
我试图向链接的父div添加一个类,如下所示:Javascript 尝试在jQuery中将类添加到父类时出错,javascript,jquery,html,Javascript,Jquery,Html,我试图向链接的父div添加一个类,如下所示: $(document).ready(function() { $(".food-result").on("click", "a", function (event) { event.preventDefault(); $(this).parent().parent().addclass('active'); return false; })
$(document).ready(function() {
$(".food-result").on("click", "a", function (event) {
event.preventDefault();
$(this).parent().parent().addclass('active');
return false;
});
我得到一个错误:
Uncaught TypeError: undefined is not a function
我做错了什么?在
addclass
方法名称中键入错误。尝试添加类 在addclass
方法名称中键入。尝试添加类 在addclass
方法名称中键入。尝试添加类 在addclass
方法名称中键入。尝试添加类 试试这个:
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
});
});
试试这个:
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
});
});
试试这个:
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
});
});
试试这个:
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
});
});
看起来您正在尝试获取可能不存在的父级的父级。这是否可行
$(document).ready(function() {
$(".food-result").on("click", "a", function (event) {
event.preventDefault();
$(this).parent().addClass('active');
return false;
});
看起来您正在尝试获取可能不存在的父级的父级。这是否可行
$(document).ready(function() {
$(".food-result").on("click", "a", function (event) {
event.preventDefault();
$(this).parent().addClass('active');
return false;
});
看起来您正在尝试获取可能不存在的父级的父级。这是否可行
$(document).ready(function() {
$(".food-result").on("click", "a", function (event) {
event.preventDefault();
$(this).parent().addClass('active');
return false;
});
看起来您正在尝试获取可能不存在的父级的父级。这是否可行
$(document).ready(function() {
$(".food-result").on("click", "a", function (event) {
event.preventDefault();
$(this).parent().addClass('active');
return false;
});
我们可以看一下相关标记(HTML)吗我们可以看一下相关标记(HTML)吗我们可以看一下相关标记(HTML)吗我们可以看一下相关标记(HTML)addclass应该是addclass-view Max的answeraddclass应该是addclass-view Max的answeraddclass应该是addclass-view Max的answeraddclass应该是addclass-view Max的答案