append anchor to a parent that contains anchor with same href attribute
<p>I'm new to SO and a jQuery newbie. I have links being dynamically created from a database into 3 different unordered lists. I'm trying to append list items from each of the two lists on the bottom to the the top list inside a new ul tag which will be a sibling to the anchor of each list item in the top list. I need to do this by matching the href attributes. I began playing around with the script below to see if I could exclude the last part of the the urls so it would be easier to match the href attributes. Any help would be greatly appreciated.</p>

<pre><code>&lt;script&gt;$(document).ready(function () {
  var href = $('ul.list li:nth-child(1) a').attr("href");
  var n = href.lastIndexOf('/');
  alert(href.substring(0, n != -1 ? n : s.length));
});
&lt;/script&gt;
&lt;/head&gt;

&lt;body&gt;
  &lt;ul class="list"&gt;
    &lt;li&gt;&lt;a href="http://www.mysite.com/index.html"&gt;My Site&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://www.google.com"&gt;Google&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://www.yahoo.com"&gt;Yahoo&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://www.cnn.com"&gt;CNN&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://www.espn.com"&gt;ESPN&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://www.tsys.com"&gt;TSYS&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  &lt;ul class="combination"&gt;
    &lt;li&gt;&lt;a href="http://www.mysite.com/index.html"&gt;My Site&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://www.google.com"&gt;To Index Page&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  &lt;ul class="combination2"&gt;
    &lt;li&gt;&lt;a href="http://www.mysite.com/index.html"&gt;My Site Too&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="http://www.yahoo.com"&gt;Yahoo Redux&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
&lt;/body&gt;
</code></pre>
