+ 1

How to let two functions work with one button/onclick

this is the example code, how can i 1. refer to the "start function" or 2. let two functions happen with one onclick <!DOCTYPEhtml> <html> <head> <script>ecmascript6+jquery</script> </head> <body> <h1 onclick="action1"> <script> function action1(){ //function 1 } function action2(){ //function 2 } </script> </body> </html> how to let function 1 happen before 2

27th Apr 2018, 4:39 PM
Roel
Roel - avatar
9 Answers
+ 2
embed both functions in a function that calls both onclick="Alpha()" function Alpha(){ action1(); action2(); } lol...its the same as 怌ļ¼Øļ¼”ļ¼°ļ¼°ļ¼¹ ļ¼“ļ¼Æ ļ¼Øļ¼„ļ¼¬ļ¼°ć€ to helps solution ,just more tidy
27th Apr 2018, 4:52 PM
Hannah
Hannah - avatar
27th Apr 2018, 4:54 PM
Hannah
Hannah - avatar
+ 2
$(document).ready (function(){ $('h1').click (action1); $('h1').click (action2); }); The only problem is this will put the action on all h1 tags so use an id instead or use better selector. if you want to know more about how this works let me know.
27th Apr 2018, 6:35 PM
Nommer101
Nommer101 - avatar
0
Thats not nice, because i have to do it 64 times and action 2 is very long šŸ˜­šŸ˜­šŸ˜­
27th Apr 2018, 4:44 PM
Roel
Roel - avatar
0
but is this possible onclick="action1()" onclick="action2()" function Alpha(){ action1(); action2(); }
27th Apr 2018, 4:56 PM
Roel
Roel - avatar
0
because otherwise i habe to do this onclick="clearall" onclick="action1" onclick="action2" function clearall(){} function action1(){} function action2(){} where you have to press clearall before all other actions
27th Apr 2018, 4:59 PM
Roel
Roel - avatar
0
i know but is there not something like cmd programs called goto which refers to a function like this :alpha cls(clears everything) :action1 action1 break/timeout goto alpha this will do action 1 and wait for an users response before clearing everything but isnt there something like goto (function) in js?
27th Apr 2018, 5:11 PM
Roel
Roel - avatar
0
Kaimi , Nommer101 ill try both of your solutions, but i think its (if it works) shorter to uses kaimi's code
27th Apr 2018, 8:42 PM
Roel
Roel - avatar