Dzięki za podpowiedź, dzięki za przykład na pewno to wykorzystam, dopiero zacząłem się uczyć js, rozwiązałem to tak, zostawiam może komuś się przyda, pozdrawiam
$( "#a1" ).click(function() {
var text = $( this ).val();
$( "#y" ).val( text );
$( "#c" ).text( text );
$( ".button-pojemnik" ).css({"background-color": "white"});
$( "#a1" ).css({"background-color": "green"});
$( "#c" ).css({"background-color": "green"});
});
$( "#a2" ).click(function() {
var text = $( this ).val();
$( "#y" ).val( text );
$( "#c" ).text( text );
$( ".button-pojemnik" ).css({"background-color": "white"});
$( "#a2" ).css({"background-color": "green"});
$( "#c" ).css({"background-color": "green"});
});
$( "#a3" ).click(function() {
var text = $( this ).val();
$( "#y" ).val( text );
$( "#c" ).text( text );
$( ".button-pojemnik" ).css({"background-color": "white"});
$( "#a3" ).css({"background-color": "green"});
$( "#c" ).css({"background-color": "green"});
});
$( "#a4" ).click(function() {
var text = $( this ).val();
$( "#y" ).val( text );
$( "#c" ).text( text );
$( ".button-pojemnik" ).css({"background-color": "white"});
$( "#a4" ).css({"background-color": "green"});
$( "#c" ).css({"background-color": "green"});
});
$( "#a5" ).click(function() {
var text = $( this ).val();
$( "#y" ).val( text );
$( "#c" ).text( text );
$( ".button-pojemnik" ).css({"background-color": "white"});
$( "#a5" ).css({"background-color": "green"});
$( "#c" ).css({"background-color": "green"});
});
$( "#a6" ).click(function() {
var text = $( this ).val();
$( "#y" ).val( text );
$( "#c" ).text( text );
$( ".button-pojemnik" ).css({"background-color": "white"});
$( "#a6" ).css({"background-color": "green"});
$( "#c" ).css({"background-color": "green"});
});
$( "#a7" ).click(function() {
var text = $( this ).val();
$( "#y" ).val( text );
$( "#c" ).text( text );
$( ".button-pojemnik" ).css({"background-color": "white"});
$( "#a7" ).css({"background-color": "green"});
$( "#c" ).css({"background-color": "green"});
});
$( "#a8" ).click(function() {
var text = $( this ).val();
$( "#y" ).val( text );
$( "#c" ).text( text );
$( ".button-pojemnik" ).css({"background-color": "white"});
$( "#a8" ).css({"background-color": "green"});
$( "#c" ).css({"background-color": "green"});
});
$( "#a9" ).click(function() {
var text = $( this ).val();
$( "#y" ).val( text );
$( "#c" ).text( text );
$( ".button-pojemnik" ).css({"background-color": "white"});
$( "#a9" ).css({"background-color": "green"});
$( "#c" ).css({"background-color": "green"});
});
$( "#a10" ).click(function() {
var text = $( this ).val();
$( "#y" ).val( text );
$( "#c" ).text( text );
$( ".button-pojemnik" ).css({"background-color": "white"});
$( "#a10" ).css({"background-color": "green"});
$( "#c" ).css({"background-color": "green"});
});
$( "#a11" ).click(function() {
var text = $( this ).val();
$( "#y" ).val( text );
$( "#c" ).text( text );
$( ".button-pojemnik" ).css({"background-color": "white"});
$( "#a11" ).css({"background-color": "green"});
$( "#c" ).css({"background-color": "green"});
});
$( "#a12" ).click(function() {
var text = $( this ).val();
$( "#y" ).val( text );
$( "#c" ).text( text );
$( ".button-pojemnik" ).css({"background-color": "white"});
$( "#a12" ).css({"background-color": "green"});
$( "#c" ).css({"background-color": "green"});
});
$( "#a13" ).click(function() {
var text = $( this ).val();
$( "#y" ).val( text );
$( "#c" ).text( text );
$( ".button-pojemnik" ).css({"background-color": "white"});
$( "#a13" ).css({"background-color": "green"});
$( "#c" ).css({"background-color": "green"});
});
$( "#a14" ).click(function() {
var text = $( this ).val();
$( "#y" ).val( text );
$( "#c" ).text( text );
$( ".button-pojemnik" ).css({"background-color": "white"});
$( "#a14" ).css({"background-color": "green"});
$( "#c" ).css({"background-color": "green"});
});
$( "#a15" ).click(function() {
var text = $( this ).val();
$( "#y" ).val( text );
$( "#c" ).text( text );
$( ".button-pojemnik" ).css({"background-color": "white"});
$( "#a15" ).css({"background-color": "green"});
$( "#c" ).css({"background-color": "green"});
});
$( "#a16" ).click(function() {
var text = $( this ).val();
$( "#y" ).val( text );
$( "#c" ).text( text );
$( ".button-pojemnik" ).css({"background-color": "white"});
$( "#a16" ).css({"background-color": "green"});
$( "#c" ).css({"background-color": "green"});
});
Przerobiony, great
let buttons = document.getElementsByName("btn-poj");
for(const button of buttons) {
button.addEventListener("click", buttonsValue);
}
function buttonsValue() {
document.getElementById("c").innerHTML = this.value;
}