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>
7 ответов
+ 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";
}
+ 7
Not a question
+ 4
@Manual It is a question he wants to reverse the onclick event with another click.
+ 3
Certainly
I just use unary operator (cond?exec cond true:exec cond false) for shorter of code
+ 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];
}
+ 1
can you tell me how can i do that?
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??