John Smith John Smith - 5 months ago 9x
Javascript Question

Change class on click not working?

Trying to change the class of an item with jQuery, but I can't seem to make it work. For some reason, nothing at all is happening.


<script src=""></script>
$("#theSpinner").click(function() {

<a href="#" id="reload">
<img src="spinbut.png" style="width:100px;height:100px;" id="theSpinner" class="notspinning">

I've tried with:

$("#theSpinner").click(function() {

aswell as
instead of
, and with an
to a javascript function containing the addClass / removeClass part.

I really don't know what's the problem, but any way around this bull would make me very happy.


Try wrapping your jQuery code within a "document-ready" block to ensure that jQuery has been loaded prior to calling your function :

    // Example of a document ready function
        // When jQuery has loaded, wire up this function
        $("#theSpinner").click(function() {


You can see a working example of this in action here and demonstrated below :

enter image description here