Jquery下一个相邻的选择器与$(this)
我怎么能用$(this)使用相邻的选择器“+”。
我需要帮助注释行//这不起作用:
$(".ExpandCollapse").click(function () { if ($(this).nextUntil('.Collapsable').is(':visible')) { //this doesnt work $(this + ".Collapsable").hide(); } else { //this doesnt work $(this + ".Collapsable").show(); } });
你能帮我个忙吗?
非常感谢提前。
最好的祝福。
何塞
使用next()
$(this).next(".Collapsable").hide();
或者干脆:
$(this).next().hide();
您还可以减少隐藏和显示的两个语句:
$(this).next().toggle();
this
是对DOM element
调用DOM element
的引用。 你不能将string
到那个。
所以你要么直接用this
来对它采取行动
$(this).hide();
或者你可以从那里走过DOM
$(this).next().hide(); $(this).prev().hide(); $(this).closest('.Collapsable').hide(); // another 200 methods