简体   繁体   English

选择表中具有类的下一个元素

[英]selecting next element with class in table

I have a Task list in a table with 3 columns and multiple rows. 我在具有3列和多行的表中有一个任务列表。 In column 1 I have a checkbox. 在第1栏中,我有一个复选框。 In column 2 I have some text and in column 3 I have a date and two icons which are hidden initially. 在第2列中有一些文本,在第3列中有一个日期和两个最初被隐藏的图标。 When the checkbox is clicked I add a class to the row in which the clicked checkbox is contained. 单击复选框后,我将一个类添加到包含单击复选框的行中。 The class marks the item as "done". 班级将该项目标记为“完成”。 But adding the class alone is not enough, I also want to show the two icons which are hidden initially. 但是仅添加类是不够的,我还想显示最初隐藏的两个图标。 So I only want to show the two on the row in which the clicked checkbox is contained. 因此,我只想在包含单击复选框的行上显示两个。

Have been fooling around with next and parent and the rest of the family but not successfully. 一直在与下一个,父母和家人其他成员鬼混,但没有成功。

Any help on this would be sweet! 在这方面的任何帮助将是甜蜜的!

at the moment what I have jquery wise is this 目前我有jQuery明智的是

$('.task-checkbox').click(function() {
  $(this).closest('tr').toggleClass('task-done');
  $(this).parent().next('.done-n-delete-icons').toggle();
});

created a jsfiddle here http://jsfiddle.net/zf7HH/1/ 在这里http://jsfiddle.net/zf7HH/1/创建了一个jsfiddle

Else , no need to toggle that other class, just use the one applied to tr : 否则,无需切换其他类,只需使用应用于tr的那个类:

.task-done .done-n-delete-icons {
    display:block;
}

DEMO 演示


With external ressource fixed : DEMO 固定外部资源: DEMO

You need to go up one more parent and then use the find method. 您需要再上一位父母,然后使用find方法。

http://jsfiddle.net/zf7HH/2/ http://jsfiddle.net/zf7HH/2/

$('.task-checkbox').click(function() {
    $(this).closest('tr').toggleClass('task-done');
    $(this).parent().parent().find('.done-n-delete-icons').toggle();
});
$('.task-checkbox').click(function() {
  $(this).closest('tr').toggleClass('task-done');
  $(this).closest('tr').find('.done-n-delete-icons').toggle();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM