Exclusion of the contents of the list in the window



  • Exclusion of the contents of the list element in the window alert It doesn't work! Please tell me what the mistake is. Example of code:

    <html>
      <head>
        <script type="text/javascript">
        function (){
        var li_elements = document.getElementsByTagName('li');
        for(var i=0; i< li_elements.length; i++)
        {
        li_elements[i].onclick = function()
        {
          alert(li_elements[i].innerHTML);
        }
        }
        }();
        </script>
      </head>
      <body>
        <form>
          <ul>
            <li>Первый</li>
            <li>Второй</li>
            <li>Третий</li>
          </ul>
        </form>
      </body>
    </html>
    


  • alert(li_elements[i].innerHTML);
    

    In the context of the function, neither li_elements nor i are defined. Do that.

    alert(this.innerHTML);
    


Log in to reply
 


Suggested Topics

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