ruthless
ruthless

Reputation: 309

JavaScript doesn't show on webpage?

<!DOCTYPE html>

<head>
<title>Cookie Clicker</title>
 </head>

 <body>
 <div id="JS"></div>


<script>
var cookies = 0;

function addCookies(){
    cookies += 1;
    getElementById("JS").innerHTML="Cookies: " + cookies;
}
 getElementById("JS").innerHTML="Cookies: " + cookies;

</script>

<button onclick='addCookies()'>Add Cookies</button>

</body>

</html>

The addCookies() doesn't work. It is supposed to say in the browser Cookies: variablecookies. Could someone explain it to me? All it shows in the browser is the button.

Upvotes: 0

Views: 70

Answers (3)

Sumit
Sumit

Reputation: 708

Don't use cookies as a variable this is a reserved variable. and check the exact error through developer tool may help more.

Upvotes: 0

Alex
Alex

Reputation: 11255

There is no getElementById function in native javascript. Use document.getElementById method.

Upvotes: 1

Anthed
Anthed

Reputation: 149

Use document.getElementById() or $("#your_id") with jQuery

Upvotes: 0

Related Questions