JSFiddle - React, Tailwind, and code Playground
by Sergei Sokolov
HTML
<input type="text" class="answer-inpt">
<div class="number">
<a href="#" class="button">1</a>
<a href="#" class="button">2</a>
<a href="#" class="button">3</a>
<a href="#" class="button">4</a>
</div>
CSS
.button {
display: inline-block;
width: 30px;
height: 30px;
text-align:center;
border:1px solid #CCC;
margin: 5px;
}
JavaScript
/**
* для вопроса https://qna.habr.com/q/928717
* Как при нажатие на любой элемент массива вивести значения?
*/
const answer = document.querySelector('.answer-inpt')
const buttonAll = document.querySelectorAll('.button')
const onclick = function() {
answer.value += this.textContent;
}
buttonAll.forEach(button => button.addEventListener('click', onclick));