Skip to content

Instantly share code, notes, and snippets.

@davojta
Created August 27, 2019 17:11
Show Gist options
  • Select an option

  • Save davojta/16a031c90a3c8521be4c842d9c562a19 to your computer and use it in GitHub Desktop.

Select an option

Save davojta/16a031c90a3c8521be4c842d9c562a19 to your computer and use it in GitHub Desktop.
js_question
<body>
    <button>0</button>
    <button>1</button>
    <button>2</button>
    <button>3</button>
    <button>4</button>
</body>
var buttons = document.getElementsByTagName('button');
for (var i = 0; i < buttons.length; i++) {
    buttons[i].onclick = function () {
        alert( i );
    }
}

Что выведется при клике на кнопку с номером 1? Почему?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment