JQuery next neighboring selector with $ (this)

How can I use the adjacent "+" selector with $ (this).

I need help with commented out lines with // this doesn't 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?

Thank you very much in advance.

Best wishes.

Jose

+6
javascript jquery
source share
3 answers

Use next()

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

Or simply:

 $(this).next().hide(); 
+9
source share

You can also reduce the availability of two operators for hiding and displaying:

 $(this).next().toggle(); 
+2
source share

this is a reference to a DOM element call. You cannot execute string .

So you can directly use this to act on it

 $(this).hide(); 

or you can go through the DOM from there

 $(this).next().hide(); $(this).prev().hide(); $(this).closest('.Collapsable').hide(); // another 200 methods 
+1
source share

All Articles