Fill the input on the click



  •  <input id="input">
     <ul id="ul">
          <li>Текст 1</li>
          <li>Текст 2</li>
          <li>Текст 3</li>
     </ul>
    

    How to fill a structure like this input text li What's that?



  • let lis = document.querySelectorAll("li");
    for (let i = 0; i < lis.length; i++) {
        lis[i].addEventListener("click", function() {
            replaceToInput(lis[i]);
        });
    }
    
    function replaceToInput(elem) {
        input = document.getElementById("input");
        input.setAttribute("value", elem.innerHTML);
    }
    

    Objection, now the code works.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2