Trigger An Event Multiple times | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Trigger An Event Multiple times

How do I trigger the event more than once. This is the code: //HTML <html onclick="clicked()"> <body> <div id="wraps"> <div class="head"></div> <div class="body"></div> <div class="leftH"></div> <div class="rightH"></div> </div> <script> function clicked() { var jump = document.getElementById("wraps"); jump.classList.add("wraps"); } </script> </body> </html> //CSS .wraps { animation: jump 0.4s linear forwards; } @keyframes jump { 0%{top: 263px;} 60%{top: 200px;} 100%{top: 263px;} } Hope someone help me out

26th Aug 2020, 3:56 PM
Ibrahim Yusuf
Ibrahim Yusuf - avatar
12 Answers
+ 3
Ibrahim Yusuf hi, Not sure this is the most efficient way to do it, but it will works : As it seems once you first click, the class is added as expected but then as the class is already set, the following clicks kind of ignore the repetition. To go around that you can add, in your function after the jump.classList.add(); setTimeout(()=>{ jump.classList.remove("wraps")},300);
26th Aug 2020, 6:02 PM
EmmanueLZ.
EmmanueLZ. - avatar
+ 3
https://code.sololearn.com/W69uG45Pn3Cf/?ref=app Ibrahim Yusuf this might help you to learn setInterval.
26th Aug 2020, 4:25 PM
Rohit
+ 3
EmmanueLZ. It works, That was great Idea, Thank youuu!
27th Aug 2020, 3:21 PM
Ibrahim Yusuf
Ibrahim Yusuf - avatar
+ 2
Using setInterval 🙌
26th Aug 2020, 4:12 PM
Namit Jain
Namit Jain - avatar
+ 2
Ibrahim Yusuf but you have already completed the JavaScript course
26th Aug 2020, 4:23 PM
Namit Jain
Namit Jain - avatar
+ 1
Namit Jain Yeah, but I mean I'm still practicing.
26th Aug 2020, 4:25 PM
Ibrahim Yusuf
Ibrahim Yusuf - avatar
+ 1
RKK Thanks. Actually I know how to use setInterval but I don't it can help with my code. let me share it so u can see
26th Aug 2020, 4:28 PM
Ibrahim Yusuf
Ibrahim Yusuf - avatar
26th Aug 2020, 4:29 PM
Ibrahim Yusuf
Ibrahim Yusuf - avatar
+ 1
Namit Jain Thank you
26th Aug 2020, 4:39 PM
Ibrahim Yusuf
Ibrahim Yusuf - avatar
+ 1
hi
27th Aug 2020, 10:32 PM
Reza Yari
0
@Namit Jain Can u please code it. I'm still learning javascript
26th Aug 2020, 4:14 PM
Ibrahim Yusuf
Ibrahim Yusuf - avatar
0
You can take idea from this code Because the gravity in your code is not working correctly https://code.sololearn.com/WmM0Du149I4z/?ref=app
26th Aug 2020, 4:32 PM
Namit Jain
Namit Jain - avatar