Вы добавляете обработчик click
к кнопке дважды, но удаляете его только один раз. Удалите второе добавление обработчика, и оно работает.
var spot = document.getElementById("spot");
spot.addEventListener("click", spotClick);
function spotClick() {
// spot.addEventListener("click", spotClick); <-- PROBLEM IS HERE
let popUp = document.getElementById("spotPopUp");
if (popUp.style.visibility == "visible") {
popUp.style.visibility = "hidden";
} else {
popUp.style.visibility = "visible";
}
spot.removeEventListener("click", spotClick);
}
<input type="button" value="ADD SPOT" id="spot" />
<div id="spotPopUp" style="visibility:hidden;">
<h3>Add a Marker</h3>
<a onclick="spotClick()"><p>Cancel</p></a>
<a onclick="saveMarker()"><p>Add Marker</p></a>
</div>
И вы можете значительно упростить этот код, если уберете встроенные обработчики событий и CSS:
// Get references to the elements you'll need to work with just once
let popUp = document.getElementById("spotPopUp");
let cancel = document.querySelector(".cancel");
let add = document.querySelector(".addMarker");
// Do your event binding in JavaScript, not inline in HTML
document.getElementById("spot").addEventListener("click", spotClick);
cancel.addEventListener("click", spotClick);
add.addEventListener("click", saveMarker);
function spotClick() {
// Just toggle the use of the hidden class.
// No removeEventListener, if/then/else or inline style manipulation needed.
popUp.classList.toggle("hidden");
}
function saveMarker(){
// code here
}
/* Use CSS classes instead of inline CSS */
.hidden { display:none; }
<!--
Don't use self-terminating syntax, it's only needed in XHTML and can
lead to confusion when not used properly.
Don't use inline CSS or JavaScript. Separate your languages.
Don't use <a> tags just for click event handling. Just about every
HTML element supports a click event.
-->
<input type="button" value="ADD SPOT" id="spot">
<div id="spotPopUp" class="hidden">
<h3>Add a Marker</h3>
<p class="cancel">Cancel</p>
<p class="addMarker">Add Marker</p>
</div>