JSFiddle - React, Tailwind, and code Playground

by Brett Gaynor

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<id id="id-2">Test</id>

JavaScript

var count = parseInt(localStorage.getItem("count"), 10) || 0;
function loadMyPage() {
		console.log(count);
    if (count >= 3) {
        mockHtmlReq();
    }
}

$(document).ready( function () {
    loadMyPage();
    localStorage.setItem("count", count += 1);
/*     $("#id-2").on("click", function() {
        localStorage.setItem("count", count += 1);
        loadMyPage();
    }); */
});

// This just mocks at request for HTML content.
// NOT NEEDED FOR THE FUNCTION OF THE CODE ABOVE.
function mockHtmlReq() {
  fetch("/echo/html/", {
    method: "POST",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded; charset=utf-8"
    },
    body: "html=<p>hello world</p>"
  })
  .then((response) => response.text())
  .then((responseText) => {
    document.querySelector("#id-2").innerHTML = responseText
  })
  .catch((error) => {
    console.error(error)
  })
}