使用Jquery nearest()函数?
这是我的HTML:
click here This is what I'd like to display
我目前有这个JQuery代码,
$(document).ready(function(){ $(".r3c").hide(); $('.show_r3c').click(function() { $(this).closest('.r3c').toggle(); return false; }); });
由于某种原因, .r3c
closest()
函数不起作用,它不会切换表行.r3c
– 我尝试使用父和其他替代品,但无法让它工作:(
为这个愚蠢的问题道歉,以及类似于我之前遇到过的问题。 只是想知道,这是什么最好的解决方案?
谢谢!
试试:
$('.show_r3c').click(function() { $(this).parent('tr').next('tr.r3c').toggle(); return false; });
nearest()查找最近的父级而不是parent-siblings-children。
你想要的东西:
$(document).ready(function(){ $(".r3c").hide(); $('.show_r3c').click(function() { $(this).closest('table').find("tr.r3c").toggle(); return false; }); });
也许这会奏效:
$(document).ready(function(){ $(".r3c").hide(); $('.show_r3c').click(function() { $(this).parent().siblings(":first").toggle(); return false; }); });