我正在尝试用 div 替换我的 radio 圈。
通过点击 div 进行选择。 所选 div 的突出显示有效。
但是,当我选择其他选项之一时,如何删除同一父项中其他子项的“选定”类?
我的 JS 现在是:
$('.option').click(function() {
$('input', this).prop("checked", true);
$(this).addClass('optionSelected');
}
最佳答案
使用 siblings()
定位兄弟 div,
$('.option').click(function() {
$('input', this).prop("checked", true);
$(this).addClass('optionSelected')
.siblings()
.removeClass('optionSelected');
});
关于html - 删除同一父 div 中其他子项的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13809304/