dip vyas

dip vyas

  • NA
  • 227
  • 38.2k

how to click to add parent class in javascript??

Jun 10 2019 1:53 AM
i use dynamically add li when i type in inputbox..it automatically add but when i close to close button in li it not working...
 
here is my code
  1. <div class="to-do">  
  2. <input type="text" id="candidate"/>  
  3. <button onclick="addItem()">add</button>  
  4. <ul id="dynamic-list"></ul>  
  5. </div>  
  6. <script>  
  7. function addItem(){  
  8. var ul = document.getElementById("dynamic-list");  
  9. var candidate = document.getElementById("candidate");  
  10. var li = document.createElement("li");  
  11. li.setAttribute('id',candidate.value);  
  12. li.appendChild(document.createTextNode(candidate.value));  
  13. ul.appendChild(li);  
  14. var button = document.createElement("button");  
  15. li.appendChild(button);  
  16. button.classList.add("mystyle");  
  17. }  
  18. </script> 

Answers (3)