Hi Alexandre,

I think an element needs to be inserted in the DOM before it can be wrapped. Try it this way:

$('<ul id="mainmenu_level2" class="mycarousel mainmenu jcarousel-skin- labau"></ul>').appendTo('#header');
$('#dsViewport h3').each(function(index){
                         var $this = $(this);
                         $('<a></a>')

                         .attr({
                                'title': 'jump to ' + $this.text(),
                                'href': '#' + $this.text(),
                                'id': 'pc-' + index
                          })
                          .text($this.text())

                          .appendTo('#mainmenu_level2')

                        .wrap('<li></li>');
});


Let us know if that does the trick. Also, I added a closing </ul> tag for you in the first line. Not sure if it's necessary, but it feels better to me. One more thing... you had 2 .attr() methods for the same element, so I combined them. :)

Cheers,

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



On Dec 13, 2007, at 10:00 AM, Alexandre Plennevaux wrote:


hi!

i'm trying to create a menu on the fly, by parsing selectors and
creating a unordered list, but i must be getting the wrap(() function
wrong as that bit does not get generated:

$('<ul id="mainmenu_level2" class="mycarousel mainmenu
jcarousel-skin-labau">').appendTo('#header');
$('#dsViewport h3').each(function(index){
                         var $this = $(this);
                         $('<a></a>')

                         .attr({
                                'title': 'jump to ' + $this.text(),
                                'href': '#' + $this.text()
                          })
.wrap('<li></li>')
                          .text($this.text())
                          .attr('id', 'pc-' + index)
                        
                          .appendTo('#mainmenu_level2');
});

in the generated html, the a elements are created, but they are not
wrapped in  LI 's, ( which do not appear anywhere by the way).

Any idea what i'm doing wrong?

--
Alexandre Plennevaux
LAb[au]

http://www.lab-au.com

Reply via email to