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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:43:01+00:00 2026-05-28T02:43:01+00:00

I am having a simple img tag within <p> tag and If I click

  • 0

I am having a simple img tag within <p> tag and If I click the img or the <p> tag the inner div should be visible and again If I click it it should hide the div.

I am getting it work for the first time but If I click the img or the <P> tag for the second the image dosent change.

I dont want the background image of the <p> should change I need it for the img tag.

<script type="text/javascript">
    jQuery(document).ready(function () {
        jQuery(".content").hide();
        //toggle the componenet with class msg_body
        jQuery(".heading").click(function () {
            var $this = $(this),
            $contentArea = $this.next('.content');

            if (!$contentArea.hasClass('active')) {
                $this.find('img').attr("src", "img/Minus.png");
                $(".content.active").slideToggle(500).removeClass('active');
                $contentArea.slideToggle(500).addClass("active");
            }
            else if ($contentArea.hasClass('active')) {
                $this.find('img').attr("src", "img/Plus.png");
                $(".content.active").slideToggle(500).addClass('active');
            }
        });
    });
</script>

This is how I’m showing it:

<div class="layer1">
    <p class="heading"><img src="img/Plus.png" alt="" style="margin:0 5px 0 0;" /></p>
    <div class="content"></div>
    <p class="heading"><img src="img/Plus.png" alt="" style="margin:0 5px 0 0;" /></p>
    <div class="content"></div>
    <p class="heading"><img src="img/Plus.png" alt="" style="margin:0 5px 0 0;" /></p>
    <div class="content"></div>
    <p class="heading"><img src="img/Plus.png" alt="" style="margin:0 5px 0 0;" /></p>
    <div class="content"></div>
</div>

Here is my fiddle

  • 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-28T02:43:01+00:00Added an answer on May 28, 2026 at 2:43 am

    This code:

    else if ($contentArea.hasClass('active')) {
        $this.find('img').attr("src", "img/Plus.png");
        $(".content.active").slideToggle(500).addClass('active');
    }
    

    Should be:

    else if ($contentArea.hasClass('active')) {
        $this.find('img').attr("src", "img/Plus.png");
        $(".content.active").slideToggle(500).removeClass('active');
    }
    

    You were hiding the active class and then adding active back onto it which was causing the problems.

    If you don’t care about more than one being expanded at a time then the code can be very simple:

    jQuery(".heading").click(function () {       
        $('img.plus, img.minus', this).toggle();
    
        $(this).next('.content')
            .slideToggle(500);        
    });
    

    http://jsfiddle.net/infernalbadger/PCgZy/3/

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

Sidebar

Related Questions

I'm having a few issues getting a simple JQuery function to work that fades
So im having a little issue getting my menu with a slidedown function work
Having trouble on a simple one. My morning tea isn't strong enough. IF div
It seems that this should be simple, but I'm having trouble figuring out how
I'm having issues with jQuery selectors (again). I'm sure this is really simple but
I'm having trouble getting my simple contact form to validate and am not sure
I am having issues with jQuery animations on a really simple slider. The first
My goal sounds fairly simple, at the moment i'm having an issue getting my
Having a simple Akka HTTP server: package org.package.some import akka.actor.{IOManager, IO, Actor} import java.net.InetSocketAddress
I'm having a simple test design problem, which I would like to solve once

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.