I am learning JavaScript and slowly wading my way to understanding why a certain page does not work 🙂
I am doing something like this:
<a onClick="removeAllMarkers(this)" href="#" >Remove All Markers</a>
With the idea that sending this is the correct way to go about things. But I think I don’t really understand the role of “this” in my current situation.
I am getting a JavaScript console error when I press on the link for “clear all markers” on this page:
http://www.comehike.com/outdoors/trees/add_spotted_trees.php?hike_id=108
The page has login credentials: test@comehike.com | password
Any ideas what I am fundamentally doing wrong and how is the best way to clear the markers[] array?
I am currently doing something like this:
if (markers)
{
for (i in markers)
{
markers[i].setMap(null);
markers[i] = null;
}
}
But that is precisely the part which is having the errors unfortunately. Suggestions? 🙂
Here is the page
Setting an array element to
nullwon’t remove it from the array.To clear an array, either assign the variable to a new empty array:
Or set its
lengthproperty to 0:Do this after looping through the array and calling
.setMap(null)on each.To only remove only the last item in an array: