[jQuery] jQuery and dynamic node generation - HELP!
Hi,
after fiddeling around to find a solutions for some hours now, maybe
you can give me a hint:
I have a navigation like this:
<div id="sub-navigation">
<ul>
<li><a name="0" href="page.html">page name</a></li>
... insert nodes with jQuery here ...
</ul>
</div>
I want to insert nodes dynamically with jQuery and the final structure
should look like this:
<div id="sub-navigation">
<ul>
<li><a name="0" href="page.html">page name</a></li>
...
<li>
<a ...>...</a>
<ul>
<li><a ...>...</a></li>
</ul>
</li>
...
</ul>
</div>
As I want to attach a click function to each link element, I started
like this:
for (var i=0;i<nav.length;i++)
{
var navEntry = $('<a href="#">' + nav[i].name + '</a>')
.click( function() {
...
}).appendTo('#sub-navigation ul');
for (var j=0;j<subnav.length;j++)
{
$('<a href="#">' + subnav[j].number + ' ' + subnav[j].name + '</a>')
.wrapInner('<li></li>')
.appendTo(navEntry);
}
}
But how do I get the correct nesting for the navigation structure
above?