after i clicked the button it'll show up "paragraph changed" then again call the previous which is the "DOG" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

after i clicked the button it'll show up "paragraph changed" then again call the previous which is the "DOG"

after i clicked the button it'll show up "paragraph changed" then again call the previous which is the "DOG". how can i do that? <!DOCTYPE html> <html> <head> <script> function myFunction() { document.getElementById("demo").innerHTML = "Paragraph changed."; } </script> </head> <body> <h1>A Web Page</h1> <p id="demo">DOG</p> <button type="button" onclick="myFunction()">Try it</button> </body> </html>

15th Sep 2017, 1:40 PM
Susovan Das
Susovan Das - avatar
7 Answers
+ 5
function myFunction(a,s){ a=document.getElementById('demo'); a.setAttribute(s='hold',a.getAttribute(s)^1); a.innerHTML=a.getAttribute(s)&1?"Paragraph changed":"DOG"; } or function myFunction(a){ a=document.getElementById('demo'); a.innerHTML=(a.youWant^=1)?"Paragraph changed.":"DOG"; }
15th Sep 2017, 1:58 PM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 7
Not a question
15th Sep 2017, 12:53 PM
Manual
Manual - avatar
+ 4
@Manual It is a question he wants to reverse the onclick event with another click.
15th Sep 2017, 1:49 PM
Ekansh
+ 3
Certainly I just use unary operator (cond?exec cond true:exec cond false) for shorter of code
16th Sep 2017, 2:22 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 3
This for like that. yes like that! function myFunction(a,s){ a=document.getElementById('demo'); s=["DOG","scream Itai","so loud","That's why","Paragraph changed."]; if(isNaN(++a.youWant))a.youWant=1; a.innerHTML=s[a.youWant%=s.length]; }
16th Sep 2017, 3:51 AM
Yanothai Chaitawat
Yanothai Chaitawat - avatar
+ 1
can you tell me how can i do that?
15th Sep 2017, 1:42 PM
Susovan Das
Susovan Das - avatar
0
thank you @Very_Hard(java & c++ & c# & py & rust & (AllHard)) i'm thinking about the logic is there any if else or loop can do the same thing??
15th Sep 2017, 8:43 PM
Susovan Das
Susovan Das - avatar