Jquery next adjacent selector with $(this)

How could i use the adjacent selector "+" with the $(this).

I would need a help with the commented lines with //this doesnt work:

$(".ExpandCollapse").click(function () {
            if ($(this).nextUntil('.Collapsable').is(':visible'))
            {
                //this doesnt work 
                $(this + ".Collapsable").hide();
            }
            else
            {
                //this doesnt work
                $(this + ".Collapsable").show();
            }
        });

Could you give me a hand?

Thanks a lot in advance.

Best Regards.

Jose


Use next()

$(this).next(".Collapsable").hide();

Or simply:

$(this).next().hide();

您还可以减少隐藏和显示两条语句:

$(this).next().toggle();

this is a reference to the DOM element of invocation. You can't concat a string to that.

So you either can directly use this to act on it

$(this).hide();

or you can walk through the DOM from there

$(this).next().hide();
$(this).prev().hide();
$(this).closest('.Collapsable').hide();
// another 200 methods
链接地址: http://www.djcxy.com/p/26678.html

上一篇: 去除div内的所有<img>标签

下一篇: jquery下一个相邻的选择器$(this)