Note that there are some explanatory texts on larger screens.

plurals
  1. POWhats wrong with this toggle function?
    primarykey
    data
    text
    <p>I am having a simple <code>img</code> tag within <code>&lt;p&gt;</code> tag and If I click the img or the <code>&lt;p&gt;</code> tag the inner <code>div</code> should be <code>visible</code> and again If I click it it should <code>hide</code> the div.</p> <p>I am getting it work for the first time but If I click the <code>img</code> or the <code>&lt;P&gt;</code> tag for the second the image dosent change.</p> <p>I dont want the background image of the <code>&lt;p&gt;</code> should change I need it for the img tag.</p> <pre><code>&lt;script type="text/javascript"&gt; 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'); } }); }); &lt;/script&gt; </code></pre> <p>This is how I'm showing it:</p> <pre><code>&lt;div class="layer1"&gt; &lt;p class="heading"&gt;&lt;img src="img/Plus.png" alt="" style="margin:0 5px 0 0;" /&gt;&lt;/p&gt; &lt;div class="content"&gt;&lt;/div&gt; &lt;p class="heading"&gt;&lt;img src="img/Plus.png" alt="" style="margin:0 5px 0 0;" /&gt;&lt;/p&gt; &lt;div class="content"&gt;&lt;/div&gt; &lt;p class="heading"&gt;&lt;img src="img/Plus.png" alt="" style="margin:0 5px 0 0;" /&gt;&lt;/p&gt; &lt;div class="content"&gt;&lt;/div&gt; &lt;p class="heading"&gt;&lt;img src="img/Plus.png" alt="" style="margin:0 5px 0 0;" /&gt;&lt;/p&gt; &lt;div class="content"&gt;&lt;/div&gt; &lt;/div&gt; </code></pre> <p>Here is my <a href="http://jsfiddle.net/PCgZy/" rel="nofollow">fiddle</a> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload