Toggle a content block

More
4 months 3 weeks 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?

Please Log in or Create an account to join the conversation.

LimeSurvey Partners
More
4 months 3 weeks ago - 4 months 3 weeks 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.

<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.
Official LimeSurvey Partner - partnersurveys.com
Last edit: 4 months 3 weeks ago by tpartner.
The following user(s) said Thank You: Joffm

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!