Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 74020

How to add a list item to an existing list using JavaScript

$
0
0

So I'm trying to add a list item to the current list items using javascript but the code is only adding the text and not replicating what the other list items look like. How can I add the list item exactly the same way the other items look?

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <link rel="stylesheet" href="css/main.css">
  <title>Practice Manipulating the DOM</title>
 </head>
<body>
  <div class="container">
    <h1></h1>
    <p class="desc"></p>
    <ul>
      <li><input> Play music</li>
      <li><input> Swim</li>
      <li><input> Bike ride</li>
      <li><input> Code</li>
    </ul>
    <div class="extra">
      <p>This is extra content you need to delete.</p>
    </div>
  </div>
  <script src="js/scripts.js"></script>
</body>
</html>
// 5: Create a new list item and add it to the <ul>
let ul = document.getElementsByTagName('ul')[0];
let li = document.createElement('li')
ul.appendChild(li).innerText ='Programmer';

Viewing all articles
Browse latest Browse all 74020

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>