Hi Xavier,

Without the full HTML of your page, I can't be sure of what you're after, but I think this should get you started anyway.

The first line gets the links for each top-level <li>. Second line clones them. Third line prepends a clone to the first nested <li> immediately following each link.

        $('ul:first > li > a').each(function() {
          var $cloned = $(this).clone();
          $(this).next('ul').find('li:first').prepend($cloned);
        });

This could probably be done more elegantly, but I'm feeling kind of ragtag this morning, so I hope you'll excuse the appearance. ;-)

--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com



On Apr 12, 2007, at 7:33 AM, xavier wrote:


Hi all,

I have a two level list :
<ul>
  <li>
  <a href="" class="to be copied"></a>
  <ul>
    <li></li>
    ...
  </ul>
 </li>

  <li>
  <a href=""  class="to be copied"></a>
  <ul>
    <li></li>
    ...
  </ul>
 </li>

I want to take all the first level a and copy them as the first
element in the list:
<ul>
  <li>
  <a href="A" class="to be copied"></a>
  <ul>
    <li><a href="A" class="copied"></a></li>
    <li></li>
    ...
  </ul>
 </li>

  <li>
  <a href="B"  class="to be copied"></a>
  <ul>
    <li><a href="B" class="copied"></a></li>
    <li></li>
    ...
  </ul>
 </li>


I know how to select each a item:

jQuery("ul ul").siblings("a")

I would know how to wrap the li around them and clone them, but once
done, I don't know how to put each of them below their list.

I've tried using .prependTo, but it copies (rightly) all the links
below every item.

Do you have any suggestion ? I'm stuck and I fell like I'm missing
something obvious.

Any idea or link to the doc I missed more than welcome!

Xavier


Reply via email to