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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:56:16+00:00 2026-05-23T21:56:16+00:00

EDIT- I would like to see it written in javascript, not jquery or a

  • 0

EDIT- I would like to see it written in javascript, not jquery or a framework please.

I know that this is something easily accomplished with jquery, but I’d like to learn the javascript behind the magic, and have been reading Dom Scripting by Jeremy Keith.

I’ve gotten a ways through the book, but doing examples where you copy code is far different from trying to build something yourself.

Right now I’m trying to do something simple (for others): Hide a paragraph element when the header2 element above it is clicked. Here is the HTML:

<div id="contentArea">
        <h2><a href="#">heading for the articles</a></h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. </p>
        <h2><a href="">Second heading for the articles</a></h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. </p>
    </div><!-- END MAIN CONTENT ---------------->

I’m trying to figure out the steps necessary to accomplish it, and can’t even really spell it out to myself in plain English, much less javascript.

I’m trying to create a block of code that would say “whenever an h2 element within the div with the id contentArea is clicked, find the next paragraph below it and hide it from view.”

  • 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-23T21:56:16+00:00Added an answer on May 23, 2026 at 9:56 pm
    // Select all h2 which are inside contentAread
    var elems = document.getElementById('contentArea').getElementsByTagName('h2'),
    i;
    
    // For each one
    for(i = 0; i < elems.length; i++)
       elems[i].onclick = function(){
            var sibling = this;
            // While there is another sibling
            while(sibling = sibling.nextSibling){
                // If sibling is a P tag
                if(sibling.nodeName == 'P'){
                    // Hide it
                    sibling.style.display = 'none';
                    // Then exit the loop
                    break;
                }
            }
        };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: I would really like to see some general discussion about the formats, their
**EDIT: There are several options below that would work. Please vote/comment according to your
I would like to see the command that Eclipse is running when I hit
I would like to edit matlab scripts in two cases (1) In matlab Command
I would like to use Emacs to edit some VB6 files but Emacs does
I would like to use the django contrib.admin pages to edit my models, but
I would like to allow the logged user to edit MediaWiki/Common.css without adding them
I would like to display certain meta data fields in the edit form based
I have a limited c++ background and I would like to edit the registry.
I'm working in Visual Studio 2008 and I would like for Edit > Outlining

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.