views:

95

answers:

2

I can't get this to work. It refreshes the page as 'undefined' so I can't even troubleshoot with Firebug. Can anyone point out to me what part of this would be returning undefined?

var locations = {
  'us-lax': {
    'name': 'Los Angeles'
  },
  'us-nyc': {
    'name': 'New York'
  }
};

// this is the order in which they'll appear
var all_locations = ['us-lax', 'us-nyc'];

function bar() {
  $('#foo').prepend('<h3>foo</h3>');
  for (i in all_locations) {
    location = locations[all_locations[i]];
    loc = $('<li></li>');
    loc.html(location['name']);
    loc.appendTo('#foo');
  }
};

$(document).ready(function() {
  bar();
});
A: 

is element with ID foo on the page?

dusoft
Yeah: <body> <ul id="foo"></ul> </body>
farkenfooken
+4  A: 

The name "location" is used by most browsers. Try using a different name for that variable.

patros
this was it -- thanks!
farkenfooken