[SOLVED] Assign same action on two different buttons on Webpage using Javascript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

[SOLVED] Assign same action on two different buttons on Webpage using Javascript

Can anyone help to merge this two functions or set same action on two different buttons. closeInputBtn[0].onclick = () => { alert() } closeInputBtn[1].onclick = () => { alert() }

17th Oct 2020, 9:54 AM
Bibek Oli
Bibek Oli - avatar
2 Answers
+ 5
closeInputBtn.forEach( btn => { btn.onclick = () => alert() })
17th Oct 2020, 10:30 AM
maf
maf - avatar
+ 2
const click = () => {} btn1.onclick = click; btn2.onclick = click;
17th Oct 2020, 10:12 AM
Gordon
Gordon - avatar