Javascript

Home Load Console Selectors CSS Form Strings If Else Array Reg Exp Date & Time setTimeout JSON Loops Objects Animation Fat Arrow Class Import IIFE undefined Tabulator.js ES6 Event Listeners AJAX Hide Elements Create Elements Checkbox ejs
O O

Weather Controls

Time Of Day
Rain
Wind Speed
Wind Direction
Clouds

Javascript : Create Elements

2022-07-18

Create unordered list tree


var ul = document.getElementById("localsites")
for (let i = 0; i < 15; i++) {
    let li = document.createElement("li"); 
    let a = document.createElement("a");
    let port = (i >= 10) ? "30"+i : "300"+i;
    a.href = `http://localhost:${port}`;
    a.setAttribute("target", "_blank");
    a.innerHTML = port;
    li.appendChild(a);
    ul.appendChild(li);
}