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

  • SEARCH
  • Home
  • 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 8344575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:24:50+00:00 2026-06-09T06:24:50+00:00

My html page content is below <div> <div> Summary 1 </div> <div style=display:none> Details

  • 0

My html page content is below

<div>
    <div>
        Summary 1
    </div>
    <div style="display:none">
        Details 1
    </div>
    <button>Read More</button>
</div>

Details content is collapsed initially. When user clicks the Read More button, I need to show details content. I can make it possible. i will define id for details div tag and javascript for onclick event of button. Using id i will change the div style display.

But i have multiple list of sections based on the back end data. so my page would be renderd like below

<div>
    <div>
        Summary 1
    </div>
    <div style="display:none">
        Details 1
    </div>
    <button>Read More</button>
</div>

<div>
    <div>
        Summary 2
    </div>
    <div style="display:none">
        Details 2
    </div>
    <button>Read More</button>
</div>

<div>
    <div>
        Summary 3
    </div>
    <div style="display:none">
        Details 3
    </div>
    <button>Read More</button>
</div>

Now How can i acheive the expand and collapse functionality when Read More button is clicked.

  • 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-09T06:24:52+00:00Added an answer on June 9, 2026 at 6:24 am

    Using plain javascript and with the strategic addition of some classes, you could do this which would make each button into a toggle that even changes it’s text according to the toggle state. Then one piece of javascript would serve for all the repeated instances of this structure and the code would be independent of the exact HTML layout of the summary, details and button (as long as they retained the same classes and were in the same container div.

    HTML:

    <div>
        <div>
            Summary 1
        </div>
        <div class="details" style="display:none">
            Details 1
        </div>
        <button class="readMore">Read More</button>
    </div>
    
    <div>
        <div>
            Summary 2
        </div>
        <div class="details" style="display:none">
            Details 2
        </div>
        <button class="readMore">Read More</button>
    </div>
    
    <div>
        <div>
            Summary 3
        </div>
        <div class="details" style="display:none">
            Details 3
        </div>
        <button class="readMore">Read More</button>
    </div>​
    

    And the javascript:

    function toggleVis(el) {
        var vis = el.style.display != "none";
        if (vis) {
            el.style.display = "none";
        } else {
            el.style.display = "block";
        }
        return(!vis);
    }
    
    (function() {
        var readMore = document.getElementsByClassName("readMore");
        for (var i = 0; i < readMore.length; i++) {
            readMore[i].onclick = function(e) {
                var vis = toggleVis(e.target.parentNode.getElementsByClassName("details")[0]);
                e.target.innerHTML = vis ? "Read Less" : "Read More";
            }
        }
    })();            
    

    Working Demo: http://jsfiddle.net/jfriend00/aMBkJ/

    Note: This would require a shim for getElementsByClassName() on older versions of IE.
    ​

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

Sidebar

Related Questions

I have the below xpath expression //div[@class=post-content]//img which runs on a html page, scanning
I m new with jquery.Below is my html table which is in content page.In
I have a php file as given below. The page generates html content which
I have the below HTML in my page <div id='divContainer1' onmouseover=ShowEditDiv(1) onmouseout=HideEditDiv(1) class='divClcContainer'> <div
To update below div : <div id=toadd data-role=content> <p>Page 1 content</p> <ul data-role=listview data-theme=g>
I want to show page loading spinner in my html page content using jquery
I have an html page with the following content: [...] <tr><td class=n><a href=play-1.0.1.zip>play-1.0.1.zip</a></td></tr> <tr><td
I have the following HTML page and the background color for the content is
I have a textarea within an HTML page into which my users paste content.
imagine this html on a page <div id=hpl_content_wrap> <p class=foobar>this is one word and

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.