Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I've pulled the success function out for readability. The key here is we're putting all the options in an array and then breaking them up into two UL's depending on the number of options they are. Instead of appending them to a premade UL, we're putting two new UL's inside a div: <code>&lt;div id='ulContainer'&gt;&lt;/div&gt;</code>.</p> <p>I've actually tested this to make sure it works. You can then apply whatever css you need to make the two UL's display how you'd like.</p> <p>I tested this before posting and it works; with a list of 5 items in your XML you'll get a list of 3 and a 2nd list of 2.</p> <p>Your problem seems to be less one of programming and more one of logic. When you encounter a difficulty, take the time to make a list of what you'd like to accomplish in small steps and that will guide you to how to make it happen in code. Rather then say "I need two UL's produced from a list of options" try:</p> <ul> <li>Get a list of options</li> <li>Determine the number of items in that list</li> <li>Make an UL out of the first half</li> <li>Make an UL out of the second half</li> </ul> <p>and if you don't know how to accomplish one of those specific tasks, post a question.</p> <pre><code>$.ajax({ type: "GET", url: "data.xml", dataType: "xml", success: parseData }); function parseData(XML) { // get an array of all the option tags from your XML var options = $(XML).find('option'); // figure out the half-way point var half_point = Math.floor(options.length/2); // we're going to create our HTML in here var spool = ''; for(x=0; x&lt;=half_point; x++) { spool += '&lt;li&gt;' + $(options[x]).attr('make') + '&lt;/li&gt;'; } $('#ulContainer').append('&lt;ul&gt;' + spool + '&lt;/ul&gt;'); // and make your second UL spool = ''; for(x=half_point+1; x&lt;options.length; x++) { spool += '&lt;li&gt;' + $(options[x]).attr('make') + '&lt;/li&gt;'; } $('#ulContainer').append('&lt;ul&gt;' + spool + '&lt;/ul&gt;'); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload