Seo Forum

Coding & Programming => JavaScript Forum => Topic started by: ORLOVA on 01-24-2020, 23:43:11

Title: How to convert li texts to links in javascript, randomly?
Post by: ORLOVA on 01-24-2020, 23:43:11
Hello folks,

How to convert li texts to links in javascript, randomly?
Title: Re: How to convert li texts to links in javascript, randomly?
Post by: Lishmalinyjames on 01-21-2021, 04:54:46
window.addEventListener('load', (event) => {
  for (var i = 0; i < 3; i++) {
    var randomLI;
    while (!randomLI || randomLI.getElementsByTagName("a").length > 0 || randomLI.innerHTML.trim().split(" ").length > 2) {
      randomLI = rando(document.getElementsByTagName("li")).value;
    }

    randomLI.innerHTML = "<a href=\"mysite.com/folder/" + randomLI.innerHTML.toLowerCase().replace(/\bamp\b|[^A-Z0-9]+/ig, "-") + "\">" + randomLI.innerHTML + "</a>";
  }
});