簡體   English   中英

Jquery下一個相鄰的選擇器與$(this)

[英]Jquery next adjacent selector with $(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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM