Note that there are some explanatory texts on larger screens.

plurals
  1. POTrying to replace last character in string, instead string duplicates
    primarykey
    data
    text
    <p>Here is a JSBin: <a href="http://jsbin.com/ofusec/2/" rel="nofollow">http://jsbin.com/ofusec/2/</a></p> <p>When you open the DIV (Customize or Personalize) the function acts as it should, truncate the "+" and replace with a "-" symbol, however when a user closes the DIV the string is duplicated and placed in.</p> <p>I would like the closing to act the same as the opening (truncate and replace last character)</p> <p>Here is the code:</p> <p>HTML:</p> <pre><code>&lt;div id="customize" class="leftDiv"&gt; &lt;span class="smallTitle" onclick="toggle_expand('customizePort');"&gt;Customize Portfolio &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; +&lt;/span&gt;&lt;br /&gt; &lt;div class="leftDivContent" id="customizePort"&gt; LAYOUT:&lt;BR /&gt; NAVIGATION:&lt;BR /&gt; BACKGROUND COLOR:&lt;BR /&gt; FONT COLOR:&lt;BR /&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="personalize" class="leftDiv"&gt; &lt;span class="smallTitle" onclick="toggle_expand('personalizePort');"&gt;Personalize Portfolio &amp;nbsp;&amp;nbsp; +&lt;/span&gt;&lt;br /&gt; &lt;div class="leftDivContent" id="personalizePort"&gt; HEADER IMAGE:&lt;BR /&gt; ARTIST STATEMENT:&lt;br /&gt; CONTACT INFORMATION:&lt;br /&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>JAVASCRIPT:</p> <pre><code>function toggle_expand(id){ var e = document.getElementById(id); var text = $(e).siblings().text(); if( $(e).css('display') === 'none' ){ $(e).slideToggle('fast', function(){ var newText = text.replace("+","-"); $(e).siblings().text( newText ); }); } else { $(e).slideToggle('fast', function(){ var newText = text.replace("-","+"); $(e).siblings().text( newText ); }); } } </code></pre>
    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.
    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