Ul list to array in jquery

I’m trying to get a UL list into an array so i can put it into different form fields


<ul id="AddressInfo">
      <li> 123 Main St. </li>
      <li> Brooklyn </li>
      <li> 11214 </li>
</ul>


i tried doing this
$(“.myUL”).click(function () {

    //    $('#mytext').val($(this).text());

    var getMyUL
    getMyUL = $(this).text();

    var arr = getMyUL.split('    ');
    		alert(arr[0]);
    $('#Address').val(arr[1]);
    $('#ApartmentNumber').val(arr[2]);

});

and the above doesn’t work in IE :confused:

but it just way to unstable… i was reading Jquery has toArray but not sure how to do it. I’m a php developer so i’m thinking how to do it in php lol

You can use $(‘li’, this) which gives you the list items as an indexable array.

For example:


$(".myUL").click(function () {
    var address = $('li', this),
        street = $(address[0]).text(),
        suburb = $(address[1]).text(),
        postcode = $(address[2]).text();

    ...
});

interesting… so… it automatically puts it into an array? based on your example i was over thinking it.