0

I have written the following JavaScript code it works fine on Google Chrome Version 34.0.1847.137 but not on Firefox 29.0.1. Found the problem on Mac OSX 10.9 but have been able to recreate it on Ubuntu 14.04. I have even ran Firefox in safemode. I am very new to JavaScript and am trying to create at Tic Tac Toe Game. Thanks in advance for any help you provide.

    <!doctype html>

<html lang="en">
<head>
    <style>
        .Square {
            width: 40px;
            height: 40px;
            text-align: center;
            font-size: 18pt;
            font-weight: bold;
            font-family: Verdana;
        }
    </style>


<script>

    function startGame() {
        document.turn = "X";

        setMessage(document.turn + " gets to start.");
    }

    function setMessage(msg) {
        document.getElementById("message").innerText = msg;
    }


</script>
</head>

<body onload="startGame();">
    <h1>Welcome</h1>

    <div id="message">messages will go here</div>

</body>

  • 2
    What error do you get in the console? – ThePixelPony May 19 '14 at 16:34
  • 1
    What "doesn't work"? Do you get errors? Is there expected output? Provide more details than it works in chrome but not in FF. – scrappedcola May 19 '14 at 16:40
  • I made a JS Fiddle for you: http://jsfiddle.net/eZwww/ – aapierce May 19 '14 at 16:40
  • @scrappedcola I tested it myself. No Errors. No console output. Expected result is that `div#message` changes its text to "X gets to start.", but that doesn't happen. – aapierce May 19 '14 at 16:44
  • @aapierce - That's all good and well but the OP needs to learn how to properly ask a question. It will help them not only here, but in other places where they might ask. I was providing feed back on the question. You making the fiddle for them and giving the details does nothing toward making the OP a better developer :) – scrappedcola May 19 '14 at 16:47

1 Answers1

2

Propably because of innerText. See this question for further information.

Try using innerHTML / textContent instead:

document.getElementById("message").innerHTML = msg;

Community
  • 1
  • 1
RienNeVaPlu͢s
  • 7,442
  • 6
  • 43
  • 77