Jquery的removeClass方法

标签 jquery jquery-selectors

我的主 div 的 ID 为 mvrContentFormDiv。里面有 4 个子 div,ID 分别为 reportFileURLUploadReportDatereportTitlereportImageURL

其中每一个都有一个错误类。现在,我正在使用以下代码单独删除该类,但想使用父 DIV 中的 removeClass

$("#reportFileURL").removeClass("error");
$("#uploadReportDate").removeClass("error");
$("#reportTitle").removeClass("error");
$("#reportImageURL").removeClass("error");

谁能解释一下我该怎么做?

最佳答案

您可以使用children()方法或child selectormvrContentFormDiv中选择它们:

$('#mvrContentFormDiv > .error').removeClass('error');

$('#mvrContentFormDiv').children('.error').removeClass('error');

关于Jquery的removeClass方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10211812/

相关文章:

javascript - 任何 Javascript/Jquery 库来验证 SQL 语句?

javascript - 0x800a138f - JavaScript 运行时错误 : The value of the property '$' is null or undefined, 不是函数对象

ruby-on-rails - Rails 远程链接处理为 JS,然后为 HTML

JQuery 查找类最接近的父级

jQuery 选择器 : exclusive OR

jquery-selectors - jQuery - 检查元素的存在

jquery - jquery 中的选择器 - 获取 rel 属性

jquery - 如何在 ember 集成测试中聚焦/模糊某个组件?

javascript - jQuery next() 在哪里使用它

javascript - 动态添加数据到 HTML 页面