const key = 'length';
localStorage[key] = 100;
console.log(localStorage[key]); // 0
console.log(localStorage.getItem(key)); // null
const key = 'length';
localStorage.setItem(key, 100);
console.log(localStorage[key]); // 1
console.log(localStorage.getItem(key)); // 100 (строкой)
Note: It's recommended to use the Web Storage API (setItem, getItem, removeItem, key, length) to prevent the pitfalls associated with using plain objects as key-value stores.
$(window).on('mouseleave', function(e){
if (e.clientY <= 0) {
console.log('Куда собрался?');
}
});
$('#wrapper').on('mouseleave', function(e){
if (e.clientY <= 0) {
console.log('Куда собрался?');
}
});
console.log(Object.entries(obj).reduce((max, n) => n[1] > max[1] ? n : max).join(': '))
.your-block img {
// styles
}
document .querySelector("#close").addEventListener("click", () =>clearTimeout(cityRemoveTime));
() => // your func
let xhr = new XMLHttpRequest();
xhr.open("GET", "https://ipinfo.io");
xhr.send();
xhr.addEventListener("load", function() {
if (xhr.status != 200) {
alert(`Ошибка ${xhr.status}: ${xhr.statusText}`);
} else {
let rawHTML = xhr.response;
let parsedDOM = new DOMParser().parseFromString(rawHTML, 'text/html').documentElement.childNodes[2]; // получаем сразу body
console.log(parsedDOM.querySelectorAll(".json-widget-entry")[3]); // поиск внутри тега body
}
});
ipinfo.io
предоставляет API, есть бесплатный план (до 50 тыс. запросов в месяц)$.get("https://ipinfo.io", function(response) {
console.log(response.ip, response.country);
}, "jsonp")
{
"ip": "134.209.xxx.xxx",
"city": "Clifton",
"region": "New Jersey",
"country": "US",
"loc": "40.8344,-74.1377",
"org": "AS14061 DigitalOcean, LLC",
"postal": "07014",
"timezone": "America/New_York",
"readme": "https://ipinfo.io/missingauth"
}