Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8931295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:04:58+00:00 2026-06-15T09:04:58+00:00

I have an ordered list which when each item is clicked it will toggle

  • 0

I have an ordered list which when each item is clicked it will toggle show/hide a corresponding div however, I am really unsure of how to do this in a mannor that works best. I know how to do it if I give each item an id or class but I’m sure there is a better way than writing lines and lines of code if it was a big list.

Basically what I have is this:

<ol>
  <li id="no1">Money Savings</li>
  <p id="reasonText">
  Some text....
</p>
  <li>Stable Fares</li>
  <p id="reasonText2">
  Some text...</p>
<li>Reason 3</li>
<p id="reasonText3">Some text...</p>

etc….

JQuery:

 $("#no1").click(function(){
     $("#reasonText").slideToggle('slow')

Is there a better way to iterate through each li and show or hide the div that follows other than basically repeating what I have in my jquery?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:05:00+00:00Added an answer on June 15, 2026 at 9:05 am

    Using all classes instead of ids would be a better way of doing this:

    <ol>
      <li class="reason">Money Savings <p class="reasonText">Some text....</p></li>
      <li class="reason">Stable Fares <p class="reasonText">Some text...</p></li>
      <li class="reason">Reason 3 <p class="reasonText">Some text...</p></li>
    </ol>
    

    The jQuery would then be as follows:

    $('.reasonText').hide(); //hide all the reason text
    $('.reason').on('click', function() {
      $(this).children('.reasonText').slideToggle('slow');
    });
    

    http://jsfiddle.net/XtUFn/

    I moved the <p> tags into the <li> tags because only <li> tags can appear in <ol> tags. If you want to keep your markup with the exception of changing ids to classes.

    <ol>
      <li class="reason">Money Savings</li>
      <p class="reasonText">Some text....</p>
      <li class="reason">Stable Fares</li>
      <p class="reasonText">Some text...</p>
      <li class="reason">Reason 3</li>
      <p class="reasonText">Some text...</p>
    </ol>​
    

    The jQuery would be as follows:

    $('.reasonText').hide(); //hide all the reason text
    $('.reason').on('click', function() {
      $(this).next('.reasonText').slideToggle('slow');
    });​
    

    http://jsfiddle.net/XtUFn/1/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a un-ordered list of links, each of which contains some text and
I have an ordered list which I have styled in two ways: Coloured the
I have a List of objects which are ordered. I would like to remove
I have an ordered list which uses large Georgia for the numbering and smaller
I have an ordered list of movies. Each movie has a name and a
I have two std::list , which each one has a positional vector m_Pos .
I have a nested oredered list which i m animating using this code... var
I have an ordered list in my Word document, and I want to add
We have an ordered list <ol> <li>something good</li> <li>even better</li> <li>possibly the best</li> </ol>
I have an ordered list in HTML. I would like to add styling only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.