Why did my div contents refused to swap? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why did my div contents refused to swap?

I just started a JavaScript course and don't understand why my divs did not swap contents when I click on the buttons. https://code.sololearn.com/WFlNkj5Q26Vg/?ref=app

5th Oct 2021, 12:10 PM
DN Josh
DN Josh - avatar
5 Answers
+ 2
Here you go: https://code.sololearn.com/W8MpUd63qlro/?ref=app You need to use AddEventListener, so html could see your swap function. (Also you defined swap function wrong) And finally you used InnerHTML rather than innerHTML.... But the code I've sent you works)))
5th Oct 2021, 1:02 PM
Aleksei Radchenkov
Aleksei Radchenkov - avatar
+ 2
Answer of Aleksei Radchenkov is also one way of handle this problem, but i was removed window.onload, because you call function on btn click, so nothing need to load before in js. Also i set in html onclick="swap('facebook','apple')" you misplased ", it was onclick=swap"(...)", and it is lower Camal Case for innerHTML https://code.sololearn.com/W2DwPalc3max/?ref=app
5th Oct 2021, 1:06 PM
PanicS
PanicS - avatar
+ 1
For color swap you need inside js to add style
5th Oct 2021, 1:16 PM
PanicS
PanicS - avatar
0
Aleksei Radchenkov pls I need your help here as well. Or probably you may know someone who can help. Tag him or her. 🙏🙏
5th Oct 2021, 12:13 PM
DN Josh
DN Josh - avatar
0
Sanja Panic thank you. But I thought the div color would swap as well as their content
5th Oct 2021, 1:10 PM
DN Josh
DN Josh - avatar