Hello. Help to understand, please, js not strong.

There is a code:

 $('.spoiler-body').hide(); $('.spoiler-title').click(function(){ $(this).next().slideToggle(); }); 

It is necessary that the list was initially disclosed.

  • one
    $('.spoiler-title').next().show() but generally it is simpler to put display: block in css - Alexey Shimansky
  • And it turns out when I add your code to js, ​​the list will be open, but it won't be closed anymore, right? - Michael Miller
  • Why, you are doing slideToggle , it means going to leave, then leaving ...... unless of course $('.spoiler-title').next() is a list) or you can have a completely different selector there - Alexey Shimansky
  • Please tell me <script> $ ('. Spoiler-title_r'). Next (). Show (); $ ('. spoiler-body'). hide (); $ ('. spoiler-title'). click (function () {$ (this) .next (). slideToggle ();}); </ script> correct script structure? The list is just nowhere near - Michael Miller
  • one
    Everything related to the question should be in the question - Alexey Shimansky

1 answer 1

I finished it myself, thanks for the tips.

 $('.spoiler-title_r').next().show(); $('.spoiler-title_r').click(function(){ $(this).next().slideToggle(); }); $('.spoiler-body').hide(); $('.spoiler-title').click(function(){ $(this).next().slideToggle(); });