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 7532697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:31:46+00:00 2026-05-30T05:31:46+00:00

I’m trying to code a page which has many articles. Each article’s title is

  • 0

I’m trying to code a page which has many “articles”.

Each article’s title is listed. If the viewer wants to read the article, they click the title.
This causes the div containing the article’s text to be displayed.

By default, no article’s text should be visible.

I’m having a lot of trouble dealing with the fact that every article title must only toggle it’s own text, and not all of the texts, even though they share the same class.

Is it possible to code something like this without manually giving every article text it’s own unique ID?

I was thinking I could wrap each article title + text in it’s own div. Then have some sort of check that tells it only to show visibility if the div is at the same level (i.e. is in the same div the title is in).

Could someone offer some guidance?

Thanks!

PS: I’d like to stick to a pure html/javascript solution, but I’ve tagged jquery in case there is an easy way to do it with that solution. I need to avoid PHP because this is not on a server.

  • 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-05-30T05:31:47+00:00Added an answer on May 30, 2026 at 5:31 am

    jQuery does indeed make it easy. If your HTML looks like this:

    <h1>Article 1</h1>
    <div class="content">
        <p>This is the content of article 1.</p>
    </div>
    <h1>Article 2</h1>
    <div class="content">
        <p>This is the content of article 2.</p>
    </div>
    <h1>Article 3</h1>
    <div class="content">
        <p>This is the content of article 3.</p>
    </div>
    

    Then this is all the JavaScript (w/ jQuery) you need:

    $(".content").hide();
    $("h1").click(function() {
        $(this).next().toggle("fast");
    });​
    

    Try it on JSFiddle.

    If you for some reason do not want to use jQuery (because you’re not using it for anything else and it’s too big to justify for just this, say), you could use plain JavaScript: (note: probably only works in newer browsers)

    Array.prototype.slice.call(document.getElementsByClassName('content')).forEach(function(element) {
        element.style.display = 'none';
    });
    document.body.addEventListener('click', function(e) {
        if(e.target.tagName.toLowerCase() !== 'h1') {
            return;
        }
        e.preventDefault();
        var content = e.target;
        while(content.nodeType != Node.ELEMENT_NODE || !/\bcontent\b/.test(content.className)) {
            content = content.nextSibling;
        }
        if(content.style.display === 'none') {
            content.style.display = '';
        }else{
            content.style.display = 'none';
        }
    }, false);
    

    Try it on JSFiddle.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from

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.