I have a code like this:
<div class="menuMesa">
<button class="chamad" id="chamad6">D6</button>
<button class="chamad" id="chamad20">D20</button>
<button class="chamad" id="chamad8">D8</button>
<button class="chamad" id="chamad10">D10</button>
<button class="chamad" id="chamad4">D4</button>
<button class="chamad" id="chamad12">D12</button>
</div>
Then there is another button, and I want to make a function that when its clicked it clicks in every button inside ".menuMesa". How can I do it?
3
Answers
Use
.click
function:You could do it like this:
querySelector
&querySelectorAll
with listening onclick_event
You do that you can use html
button
attribute — onclickSo first you need to create a script tag, and then we have a function called
buttonClicked
( you can rename it with any name ) and then set the onclick attribute to “buttonClicked”So your code might be like this: