+ 2

Where should i place it?

Now i know how to set an id in javascript = document.getElementById=".."; but in my code below i want to give the id fail only to the fail text. I didn't found out where i should place document.get... to give only the fail text an id. please help https://code.sololearn.com/WynbTfgw9s5M/?ref=app

23rd May 2017, 10:14 AM
TrueJu
TrueJu - avatar
3 Respostas
+ 18
<!DOCTYPE html> <html> <body> <h2>Coin Bank</h2> <p> 30 Coins for 300
lt;/p> <button onclick="myFunction()">Coins</button> <p id="demo"></p> <script> function myFunction() { demo = document.getElementById("demo")||document.getElementById("Fail!"); var txt; if (confirm("Are you sure that you want to buy 30 coins for 300$?!") == true) { txt = "Purchase succeeded!"; } else { demo.id = txt = "Fail!"; } demo.innerHTML = txt; } </script> </body> </html>
23rd May 2017, 5:26 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 17
(Notice your mistake on setting id.....)
23rd May 2017, 5:27 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 3
Thank you for this great answer :D it helped me out
23rd May 2017, 5:28 PM
TrueJu
TrueJu - avatar