jQuery script for clickNshow on a dokuwiki page
-
03-10-2019 - |
Question
I am making a dokuwiki for our company, but because the documents tend to get very large, I want to collapse the sections and only show the headers. The sections should appear when the header has been clicked.
The dokuwiki tips and tricks page shows a nice little jquery script that facilitates this click and show behaviour. I modified it so that it only applies to 'h2' and none of the other headers.
Now the only thing I want is that the level 2 sections are by default hidden. I tried to add a CSS div.level2{display:none;}
to the main page, but this does not really do the trick. It does hide the sections, but they do not appear anymore when the header is being clicked.
Is there a way to hide all sections below the h2 headers when the page loads using the javascript code?
Solution
jQuery("h2").click(function(){
jQuery("div.level2").toggle();
});
Try using this code.
The first line selects h2 and tell when its clicked it should call the function
the function toggles ur level 2 div
. . . . .