IP Address Tracker

Solution retrospective
Hi everyone! This is my very first experience with Leaflet JS and Ipify Geolocation API & there may be some bugs. So, feel free to point out the errors in my code. Currently, this project accepts IP Addresses only. The domain name functionality will be added in the future.
Although, I have a simple question. When I tried to change the values of the innerHTML properties of IP information container, the following code not worked but the second one did.
var ipOutAdd = document.getElementById("ip-add").innerHTML;
function(){
ipOutAdd = data.ip;
}
Adding innerHTML property when declaring the variable didn't let me change the value later from inside the function.
The working code snippet is below.
var ipOutAdd = document.getElementById("ip-add");
function(){
ipOutAdd.innerHTML = data.ip;
}
All explanations related to this error, are welcome.
Please log in to post a comment
Log in with GitHubCommunity feedback
- @fazzaamiarso
Hello Tharusha!
To answer your question why it doesn't work, that is because you are re-initialize the value of ipOutAdd. In essence, what you are doing is this
// 1. Saving the value of "ip-add" innerHTML which is a string; var ipOutAdd = document.getElementById("ip-add").innerHTML; // 2. Replace the value of ipOutAdd with data.id. ipOutAdd = data.id;
I hope it helps! Cheers!
Join our Discord community
Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!
Join our Discord