1st May 2018, 9:24 AM
Sina
Sina - avatar
5 Answers
+ 3
<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <p id="p"></p> <button onclick="a()">Change</button> <script> var f = "Sina" var s = "Navid" var grow = true; function a(){ var x = document.getElementById("p") if(grow){ x.innerHTML = f } else { x.innerHTML = s; } if(x.innerHTML == f || x.innerHTML == s){ grow = !grow } } </script> </body> </html>
1st May 2018, 9:33 AM
Yugabdh
Yugabdh - avatar
+ 3
Ur using assignment operator in if condition use equality operator insted
1st May 2018, 9:33 AM
Yugabdh
Yugabdh - avatar
+ 3
<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <p id="x"></p> <button id="button">Change</button> <script> var f = "Sina" var s = "Navid" window.flag=false; button.onclick=function() { window.flag=!window.flag; if (window.flag) { x.innerHTML = f } else{ x.innerHTML = s; } }; </script> </body> </html>
1st May 2018, 9:42 AM
Sudarshan Rai
Sudarshan Rai - avatar
+ 3
you can also use this easy to understand
1st May 2018, 9:42 AM
Sudarshan Rai
Sudarshan Rai - avatar
+ 3
Thanks all
1st May 2018, 9:46 AM
Sina
Sina - avatar