closing an unordered list

Posted by snorpey on Stack Overflow See other posts from Stack Overflow or by snorpey
Published on 2010-03-14T10:25:50Z Indexed on 2010/03/14 10:35 UTC
Read the original article Hit count: 308

Filed under:
|
|

On a website, I want to display the main navigation as an unordered list. After 3 items I want to close that list and open a new one, so it eventually looks something like this:

<div id="navigation">
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
    </ul>
    <ul>
        <li>4</li>
        <li>5</li>
        <li>6</li>
    </ul>
</div>

The navigation is dynmically generated using jQuery + Ajax. This is what the code I'm using looks like:

$.getJSON("load.php", 
{
     some: value
},   
function(data)
{         
    $.each(data.items, function(i, item)
    {
        $('#navigation').find('ul').append('<li>' + i + '</li>');

        if(i % 3 == 0)
        {
            $('#navigation').find('ul').append('</ul><ul>');
        }
    });
});

Unfortunately, the browser doesn't interpret this right and treats the closing ul tag as a nested object of the first ul. How do I fix this?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX