[英]How to add a class to an element when thead table was click in jquery?
I want to add a class Open to li element on class Menus when user click on thead tr th of my table as below. 我想补充的类菜单一类开放给li元素当THEAD TR用户点击我的第桌子下面的。
This is my table 这是我的桌子
<div><ul>
<li class="menus">
<a></a>
<ul><li>
<table id="tableid ">
<thead>
<tr><th></th><th></th><th></th></tr>
</thead>
<tbody>
<tr id="1">
<td></td>
<td id="type1">types1</td>
<td></td>
<td id="types2">types2</td>
<td></td>
</tr>
<tr id="2">
<td></td>
<td id="type1">types3</td>
<td></td>
<td id="types2">types4</td>
<td></td>
</tr>
</tbody>
</table>
</li>
</ul>
</li></ul></div>
JS JS
$(document).on('click','#tableid thead tr th', function(){
var parents = $(this).prevAll().find('li')
console.log(parents)
});
Use .parents
and .addClass
使用
.parents
和.addClass
$(document).on('click','#tableid thead tr th', function(){
var parents = $(this).parents('li.menus').addClass('open')
console.log(parents)
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.