Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Toggle a content block

More
6 years 2 months ago #186421 by blocka
I'd like to have some content that the user can click a button to show/hide on a question. I'm using LS3 build xxx627.

Thought I could use this:

www.w3schools.com/jquery/jquery_hide_show.asp

But as soon as I click the Hide button, the page refreshes, and I see the content again (it does get hidden for a fraction of a second, but that's not too helpful).

Any suggestions?
The topic has been locked.
More
6 years 2 months ago - 6 years 2 months ago #186430 by tpartner
Replied by tpartner on topic Toggle a content block
If you add a <button> element you need to give it a type="button" attribute or it will submit the form.

Code:
<script>
  $(document).ready(function(){
    $(".my-button").click(function() {
      $("p.will-toggle").toggle();
    });
  });
</script>
 
<button type="button" class="my-button">Toggle between hiding and showing the paragraphs</button>
 
<p class="will-toggle">This is a paragraph with little content.</p>
<p class="will-toggle">This is another small paragraph.</p>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 6 years 2 months ago by tpartner.
The following user(s) said Thank You: Joffm
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose