Reputation: 219
I am trying to unset or remove a value of the jquery variable.I am updating a value to the div using the jquery. Here i show the address of the user from the latitude and longitude from api response.
Some times if the latitude and longitude value is 0 the div shows previous result.i wanted to remove the previous value and need a fresh load of the div.
Div to change the value through the jquery call.
<div id="wiPlayerLocation" class="datenTime"> </div>
The jquery i used:
var wiLats = entry.data.latitude;
var wiLons = entry.data.longitude;
var lat = parseFloat(wiLats);
var lng = parseFloat(wiLons);
var latlng = new google.maps.LatLng(lat,lng);
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'latLng': latlng }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
wiLatLongAddress = ' / ' + results[0].formatted_address;
$('#wiPlayerLocation').html(" " + wiLatLongAddress);
}
}
});
I need to reset/unset/remove the value of the variable wiLatLongAddress or remove the data from the div.
Upvotes: 0
Views: 658
Reputation: 2571
Add else and reset the value if
var wiLats = entry.data.latitude;
var wiLons = entry.data.longitude;
var lat = parseFloat(wiLats);
var lng = parseFloat(wiLons);
var latlng = new google.maps.LatLng(lat,lng);
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'latLng': latlng }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[0]) {
wiLatLongAddress = ' / ' + results[0].formatted_address;
}
else{
wiLatLongAddress = '';
}
$('#wiPlayerLocation').html(" " + wiLatLongAddress);
}
});
Upvotes: 0
Reputation: 168
You could use
$('#wiPlayerLocation').html(" ");
in the else part of if (results[0]) condition.
Upvotes: 0