Text with functionality. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Text with functionality.

Let's say we have a button that writes "Hello!" everytime you press it, and every 3 times you press it the "hello" that pops up is clickable and when you click it, it alerts "Hello world!". How would you do that?

16th Jan 2019, 7:38 PM
Ric2908
Ric2908 - avatar
4 Answers
0
My solution as described above would look like this: https://code.sololearn.com/Wmz1CNx8r2Pp/?ref=app
17th Jan 2019, 3:51 PM
Aaron Eberhardt
Aaron Eberhardt - avatar
+ 2
Create a event listener on a button for a "click" event. The function included will create a new html element with innerHTML = "Hello!"; when the event is fired. Every third time you add a further event listener on the new html element you created, that will alert "Hello world!". Hope that made sense. If not you can ask me :)
16th Jan 2019, 8:03 PM
Aaron Eberhardt
Aaron Eberhardt - avatar
+ 1
Thanks a lot! :)
17th Jan 2019, 7:42 PM
Ric2908
Ric2908 - avatar
0
Aaron Eberhardt Could you show me an example code of how would it be? I'm a little confused about what you said.
17th Jan 2019, 12:34 PM
Ric2908
Ric2908 - avatar