<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Chai aur code | DOM</title> </head> <body style="background-color: #212121; color: #fff;"> <ul class="language"> <li>Javascript</li> </ul> </body> <script> function addLanguage(langName){ const li = document.createElement('li'); li.innerHTML = `${langName}` document.querySelector('.language').appendChild(li) } addLanguage("python") addLanguage("typescript") function addOptiLanguage(langName){ const li = document.createElement('li'); li.appendChild(document.createTextNode(langName)) document.querySelector('.language').appendChild(li) } addOptiLanguage('golang') //Edit const secondLang = document.querySelector("li:nth-child(2)") console.log(secondLang); //secondLang.innerHTML = "Mojo" const newli = document.createElement('li') newli.textContent = "Mojo" secondLang.replaceWith(newli) //edit const firstLang = document.querySelector("li:first-child") firstLang.outerHTML = '<li>TypeScript</li>' //remove const lastLang = document.querySelector('li:last-child') lastLang.remove() </script> </html>
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter