title: Javascript replacing text
body: <p>There's a Collapsible Nested Script <a href="http://www.howtocreate.co.uk/jslibs/listCollapse.js" rel="nofollow">Here</a>.</p>
  
  <p>In the code if I have <code>&lt;ul&gt;Name</code> it will convert it to <code>&lt;ul&gt;&lt;a href="#"&gt;&amp;plusmn; Name&lt;/a&gt;</code>.</p>
  
  <p>However, if I already have a link like:</p>
  
  <p><code>&lt;ul&gt; &lt;a href="#"Name&lt;/a&gt;</code> it will convert it to</p>
  
  <pre><code>&lt;ul&gt;&lt;a href="#"&gt;&amp;plusmn; &lt;/a&gt;
      &lt;a href="#"&gt;Name&lt;/a&gt;
  </code></pre>
  
  <p>I want to combine them to be: <code>&lt;ul&gt;&lt;a href="#"&gt;&amp;plusmn; Name&lt;/a&gt;</code>. I'm unsure how to do that.</p>
  
  <p>I know it has to do something with</p>
  
  <pre><code>        //create a link for expanding/collapsing
          var newLink = document.createElement('A');
          newLink.setAttribute( 'href', '#' );
          newLink.onclick = new Function( 'clickSmack(this,' + oLev + ',\'' + oBsID + '\',' + oCol + ',\'' + escape(oT) + '\');return false;' );
          //wrap everything upto the child U/OL in the link
          if( oML ) { var theHTML = ''; } else {
              var theT = y[x].innerHTML.toUpperCase().indexOf('&lt;'+oT);
              var theA = y[x].innerHTML.toUpperCase().indexOf('&lt;A');
              var theHTML = y[x].innerHTML.substr(0, ( theA + 1 &amp;&amp; theA &lt; theT ) ? theA : theT );
              while( !y[x].childNodes[0].tagName || ( y[x].childNodes[0].tagName.toUpperCase() != oT &amp;&amp; y[x].childNodes[0].tagName.toUpperCase() != 'A' ) ) {
                  y[x].removeChild( y[x].childNodes[0] ); }
          }
          y[x].insertBefore(newLink,y[x].childNodes[0]);
          y[x].childNodes[0].innerHTML = oPM + theHTML.replace(/^\s*|\s*$/g,'');
          theNextUL.MWJuniqueID = oIcount++;
          compactChildren( theNextUL, oLev + 1, oBsID, oCol, oPM, oT, oML );
  </code></pre>