+ 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
3 odpowiedzi
+ 18
<!DOCTYPE html>
<html>
<body>
<h2>Coin Bank</h2>
<p> 30 Coins for 300lt;/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>
+ 17
(Notice your mistake on setting id.....)
+ 3
Thank you for this great answer :D it helped me out