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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:39:03+00:00 2026-06-03T13:39:03+00:00

I have a following problem here: in my html structure I got some div’s

  • 0

I have a following problem here: in my html structure I got some div’s and they are initially hidden. What I am trying to do is this: on click of a paragraph tag store it’s index and apply that same index to hidden div (witch also has the same index as “clicked” p tag).

For example: when I click SHOW RED DIV ‘paragraph’ show the hidden div (div with class red) with the same index as clicked p tag. My code is not working because it shows all hidden div’s and because I don’t know how to apply stored index 🙁   I hope that someone can help me… THX!!

Here’s the Fiddle

This is what I got so far:

<html>
<head>
<style type="text/css">
div{width:100px;height:100px;display:none;}
.red{background-color:red;}
.blue{background-color:blue;}
.green{background-color:green;}
</style>

<script type="text/javascript">
$(document).ready(function(){
   $("p").click(function(){
   var index=$(this).index(this);
   $('div').data('index',index).show('slow');
   });
});
</script>
</head>
<body>
<div class="red"></div>
<div class="blue"></div>
<div class="green"></div>
<span>
<p>SHOW RED DIV</p>
<p>SHOW BLUE DIV</p>
<p>SHOW GREEN DIV</p>
</span>
</body>
</html>
  • 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-03T13:39:04+00:00Added an answer on June 3, 2026 at 1:39 pm

    Use this code:

    $(document).ready(function() {
        $("p").click(function() {
            var index = $(this).index();
            $('div:eq(' + index + ')').show('slow');
        });
    });​
    

    DEMO: http://jsfiddle.net/Q96Uj/

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

Sidebar

Related Questions

I have following in my HTML code: <div id=txtHint><b>Person info will be listed here.</b></div>
I have the following problem. I have three images in my index.html: <div class
am new here. i have a slight problem; PLease look at the following code
I have the following problem: I have an HTML textbox ( <input type=text> )
Now here's a fun problem. I have an object array as the following: objRequests
I have the following html: <div class=canvas red> <div> <div class=canvas blue> <div> has
I'm new to PHP, HTML and MySQL, and have encountered the following problem: I
I have this fragment that demonstrates the problem: <html> <head> <title>height query demo</title> <script
I have the following problem: I have a webserver. This webserver is behind a
I have the following problem: On a Button-Click I POST some data to the

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.