mapid
has the last value assigned to it by the time the hover event handler is fired, so you need to make sure you have the relevant value.
Try putting the hover assignment inside an enclosure...
for (i = 0; i < Ajax.length; ++i) {
var listid = 'listitem-'+i;
var mapid = 'mapitem-'+i;
$('.list').append('<div id="'+listid+'">Lots of Text</div>');
$('.viewer').append('<div id="'+mapid+'">Here It Is</div>');
(function(listid, mapid) {
$('#'+listid).hover(function(){
$('#'+mapid).toggleClass('highlight');
});
})(listid, mapid);
}
An alternative method would be to store the associated map ID with the list item, like this...
for (i = 0; i < Ajax.length; ++i) {
var listid = 'listitem-'+i;
var mapid = 'mapitem-'+i;
$('.list').append('<div id="'+listid+'">Lots of Text</div>');
$('.viewer').append('<div id="'+mapid+'">Here It Is</div>');
$('#'+listid).data("associated-map-id", mapid);
$('#'+listid).hover(function(){
$('#'+$(this).data("associated-map-id")).toggleClass('highlight');
});
}
Either will work and they'll give the same end result. Just choose what you prefer :)