-4
I wanted to do console.log by clicking only the button, but what I did makes console log if I click anywhere can explain to me how to make console.log work only by clicking the buttons.
var div = document.querySelector("div");
addEventListener('click', item);
function item() {
console.log('click');
}
.container2 {
margin: 0 auto;
width: 335px;
padding: 10px;
background: black;
font-size: 1.1em;
text-align: right !important;
}
.container {
margin: 0 auto;
width: 335px;
padding: 10px;
background: black;
display: grid;
grid-template-columns: repeat(4, 1fr);
}
.container>div {
text-align: center;
padding: 28px 25px;
border-radius: 50%;
color: white;
margin: 0 7px 11px 0;
font-family: sans-serif;
cursor: pointer;
font-weight: bolder;
font-size: 20px;
}
.item1 {
background-color: #a5a5a5;
color: black;
}
.item2 {
background-color: #fe9e09;
}
.item3,
.item4 {
background-color: #333333;
}
.teste {
color: white;
margin-bottom: 77px;
margin-top: 441;
background: transparent;
box-shadow: none;
font-size: 80px;
}
.item4 {
grid-column: span 2;
border-radius: 70px !important;
text-align: left !important;
}
<div class='container'>
<div class="item1">AC</div>
<div class="item1">+/-</div>
<div class="item1">%</div>
<div class="item2">:</div>
<div class="item3">7</div>
<div class="item3">8</div>
<div class="item3">9</div>
<div class="item2">x</div>
<div class="item3">4</div>
<div class="item3">5</div>
<div class="item3">6</div>
<div class="item2">-</div>
<div class="item3">1</div>
<div class="item3">2</div>
<div class="item3">3</div>
<div class="item2">+</div>
<div class="item4">0</div>
<!-- <div class='item4'></div> -->
<div class="item3">,</div>
<div class="item2">=</div>
</div>
to work you have to add the
eventlistener
to the button element of your code. In the post there is no button.– Danizavtz
Dude, you got it as a dial
document.querySelector("div");
This means that when you click on the first DIV of the document it already does the console.log, you can see that even clicking off the calculator it gives the console.log, you have to give more details– hugocsl