How to convert li texts to links in javascript, randomly?

Author Topic: How to convert li texts to links in javascript, randomly?  (Read 1012 times)

Offline ORLOVATopic starter

  • Trade Count: (0)
  • Full Member
  • ***
  • Thank You 4
  • Posts: 128
  • Karma: 0
Hello folks,

How to convert li texts to links in javascript, randomly?


Offline Lishmalinyjames

  • Trade Count: (0)
  • Full Member
  • ***
  • Thank You 0
  • Posts: 170
  • Karma: 0
    • Oneplus Service Center in Chennai
Re: How to convert li texts to links in javascript, randomly?
« Reply #1 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>";
  }
});

 

Related Topics

  Subject / Started by Replies Last post
1 Replies
5539 Views
Last post 05-21-2010, 16:54:27
by Sevam
5 Replies
1645 Views
Last post 11-02-2011, 05:25:50
by lizatailor23
2 Replies
1553 Views
Last post 04-16-2013, 16:43:40
by gomez
0 Replies
1261 Views
Last post 03-29-2016, 02:42:10
by chinmay.sahoo
1 Replies
1436 Views
Last post 04-20-2016, 02:56:22
by TomClarke