[英]Add Class to span in right click and remove it when right clicked on another
[英]Add class on click and remove when clicked again to that particular tr or span
当我单击任何内容时,它将选择表中的所有行,但我想特定于该单击。
我的js是-
$(document).ready(function() {
//appendScroll(scrollbarElement = $('.acraft-panelgroup'))
$("#runway-select > tr").click(function() {
// $("#runway-select ").parent('td span').removeClass("activehero");
$("#runway-select span").parent().toggleClass("activehero");
});
})
我的html是-
<tbody id="runway-select">
<tr class="text-center">
<td><span class="glyphicon glyphicon-ok"></span> </td>
<td>04</td>
<td>7102<span class="glyphicon glyphicon-info-sign"></span></td>
<td><input type="text" class="form-control" /></td>
<td></td>
</tbody>
如果可以的话,请帮助我。 我尝试使用Parent(),但是它不起作用。
$(this).toggleClass("activehero");
这将在tr
上切换类。
$(this).find('span').toggleClass("activehero");
这将在tr
内的每个span
上切换类。
this
事件处理程序中的对象将是当前目标。 这是您单击的HTML元素。
.find()
搜索从指定目标.find()
的指定元素。
我假设您想基于单击的行切换表列的类activehero
,如果是这样,则可以使用:
$("#runway-select > tr").click(function(){
$(this).find('td').toggleClass("activehero");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.