Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery toggle text only changes once
    primarykey
    data
    text
    <p>I have the following code which should change the value of an h2 from "Show More" to "Show Less" and then back again when the parent is clicked.</p> <p>The if() tests ok and changes the text to Show Less but it will never change it back again and always displays the alert "Show More" so it just isn't detecting the else() condition.</p> <p>I have searched high and low to find out why but haven't found a solution yet.</p> <p>I know this a noob question so apologise for this but I have tried finding the solution before posting here.</p> <p>Thanks.</p> <pre><code>$('#panels &gt; .feature').click(function() { if($(this).children('h2').val('Show More')) { $(this).children('h2').text('Show Less'); alert('Show More was found'); } else { $(this).children('h2').text('Show More'); alert('Show Less was found'); } $(this).next(".info_box").animate( {'height':'toggle'}, 'slow', 'linear' ); }); </code></pre> <p>The HTML in question is:</p> <pre><code>&lt;div id="panels"&gt; &lt;div id="Email" class="feature"&gt; &lt;h1&gt;LiveContent&lt;/h1&gt;&lt;h2&gt;Show More&lt;/h2&gt; &lt;/div&gt; &lt;div class="info_box"&gt;Information will go in this div which should slide in and out.&lt;/div&gt; &lt;div id="Email" class="feature"&gt; &lt;h1&gt;Publishing Solutions&lt;/h1&gt;&lt;h2&gt;Show More&lt;/h2&gt; &lt;/div&gt; &lt;div class="info_box"&gt;Information will go in this div which should slide in and out.&lt;/div&gt; &lt;div id="Email" class="feature"&gt; &lt;h1&gt;Title 1&lt;/h1&gt;&lt;h2&gt;Show More&lt;/h2&gt; &lt;/div&gt; &lt;div class="info_box"&gt;Information will go in this div which should slide in and out.&lt;/div&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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