JSFiddle - React, Tailwind, and code Playground

by Michele Marcucci

HTML

<div id="test" data-country=""></div>

JavaScript

$(document).ready(function () {

    $.ajax({
        url: "http://ipinfo.io/",
        dataType: "json",
        async: false,
        success: function (response) {
            console.log(response);
            // Save the data into an element data attribute
            $('#test').data('country', response.country);
        }
    });

    // Retrieve the data from the element
    var storedCountry = $('#test').data('country');
    console.log(storedCountry);
});