Skip to content

Instantly share code, notes, and snippets.

@theWhiteFox
Last active October 5, 2016 13:33
Show Gist options
  • Select an option

  • Save theWhiteFox/0f46c5f17bdb7194bb4f09bde2499061 to your computer and use it in GitHub Desktop.

Select an option

Save theWhiteFox/0f46c5f17bdb7194bb4f09bde2499061 to your computer and use it in GitHub Desktop.
Pure JS button click
<div id="option">
<button class="valueButton"
value="0">0
</button>
<button class="valueButton"
value="1">1
</button>
<button class="valueButton"
value="2">2
</button>
<button class="valueButton"
value="3">3
</button>
</div>
<script>
// not strictly an array Array-Like
var buttonArray = document.getElementsByClassName("valueButton");
var getButtonValue = function () {
var attribute = this.getAttribute("value");
alert(attribute);
};
for (var i = 0; i < buttonArray.length; i++) {
buttonArray[i].addEventListener('click', getButtonValue, false);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment