JavaScript Error: Uncaught TypeError: foo is not a function
<p>For some reason JavaScript doesn't seem to recognise my function.</p>

<p>I have a button in some HTML:</p>

<pre><code>&lt;button type="button" class="btn btn-default" id="lightOn" onclick="lightOn()"&gt;On&lt;/button&gt;
</code></pre>

<p>and then a bit of JavaScript:</p>

<pre><code>function lightOn(){
    $("#lightOn").addClass("active");
    $("#lightOff").removeClass("active");
    socket.emit("setting", {"light":"on"});
}
</code></pre>

<p>When I click on the button I get the error:</p>

<blockquote>
  <p>Uncaught TypeError: lightOn is not a function</p>
</blockquote>

<p>Any idea why this won't work?</p>

<p>Thanks.</p>