我怎么能用$(this)使用相邻的选择器“+”。
我需要帮助评论一行//这不起作用:
$(".ExpandCollapse").click(function () {
if ($(this).nextUntil('.Collapsable').is(':visible'))
{
//this doesnt work
$(this + ".Collapsable").hide();
}
else
{
//this doesnt work
$(this + ".Collapsable").show();
}
});
你能帮我一把吗?
提前多多感谢。
最诚挚的问候。
何
答案 0 :(得分:12)
答案 1 :(得分:3)
您还可以减少隐藏和显示两个语句:
$(this).next().toggle();
答案 2 :(得分:1)
this
是对DOM element
调用的引用。你不能将string
连接到那个。
因此,您可以直接使用this
对其进行操作
$(this).hide();
或者您可以从那里走过DOM
$(this).next().hide();
$(this).prev().hide();
$(this).closest('.Collapsable').hide();
// another 200 methods