Im using .children(); to count a number of results pulling from a search query, but when I get a search that doesn't bring back results it still has the same count from the previous search. Is there anyway to clear it to ready it for the next search? Here is the code im using:
function results(){
var n = $("#sidebar").children().length;
$(".numresults").html("Found <span class='bright'>" + n + "</span> results in your area.");
}
This is the search function results() is in:
function searchLocationsNear(center) {
var radius = document.getElementById('radiusSelect').value;
var searchUrl = 'genxml.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius;
GDownloadUrl(searchUrl, function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName('marker');
map.clearOverlays();
var sidebar = document.getElementById('sidebar');
sidebar.innerHTML = '';
if (markers.length == 0) {
sidebar.innerHTML = '<p class="caption">No results found.</p>';
map.setCenter(new GLatLng(40, -100), 4);
return;
}
var bounds = new GLatLngBounds();
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute('name');
var address = markers[i].getAttribute('address');
var type = markers[i].getAttribute('type');
var phone = markers[i].getAttribute('phone');
var city = markers[i].getAttribute('city');
var state = markers[i].getAttribute('state');
var zip = markers[i].getAttribute('zip');
var distance = parseFloat(markers[i].getAttribute('distance'));
var point = new GLatLng(parseFloat(markers[i].getAttribute('lat')),
parseFloat(markers[i].getAttribute('lng')));
var marker = createMarker(point, name, address, type, phone, city, state, zip);
map.addOverlay(marker);
var sidebarEntry = createSidebarEntry(marker, name, address, distance, type, city, state, zip);
sidebar.appendChild(sidebarEntry);
bounds.extend(point);
}
paginate();
results();
offon();
map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
});
}