Change button text on hover over jQuery

If the text of the button is “followed” and the user hovers over it, I want the text to change to “unfollow” and change to “follow” after the user stops hanging.

Button

{%if follow%}
<button type="submit" id="status" class="button" value="True"><span>followed</span></button>

{%else%}
<button type="submit" id="status" class="button" value="False"><span>follow</span></button>

{%endif%}

JQuery

<script>
$(document).ready(function(){
    $(".button").click(function() {
        var status = $("#status").val();
        var course = $("#course").html()

        //SECTION THAT I'M HAVING TROUBLE WITH
        if ($(".button span").html() == "followed") {
            $(".button").mouseover(function() {
            $(".button span").html() = "unfollow";
            }
        }

        $.ajax({
            type: "POST",
            url: "/follow",
            data: 'status=' + status + "&course=" + course,
            success: function() {
$(".button span").html($(".button span").html() == 'followed' ? 'follow' : 'followed');
$(".button").val($(".button").val() == 'True' ? 'False' : 'True');
}
        });
        return false;
    });
});
</script>

When I run this, I get

405 Method Not Allowed

The method POST is not allowed for this resource. 

But when I delete the mouse code, it works. What is wrong with the mouse code?

Edit: Updated jQuery, which now works, outside of onclick code, with mouseout:

if ($(".button span").html() == "followed") {
$(".button").mouseover(function() {
    $(".button span").html("unfollow");
});
$(".button").mouseout(function() {
    $(".button span").html("followed");
});
}

: , , "", , "". , , mouseout ajax, "". "follow" mouseout ?

+4
3

, ");" , ...

//SECTION THAT I'M HAVING TROUBLE WITH
if ($(".button span").html() == "followed") {

    $(".button").mouseover(function() {
        // Pass the new string into .html()
        $(".button span").html("unfollow");
    });
}
+8
$(document).ready(function(){
    $('#status').hover(function() {
        $(this).find('span').text('unfollow');
    }, function() {
        $(this).find('span').text('followed');
    });
});

, . http://jsfiddle.net/sing0920/54yfg/

+2

JavaScript, . CSS. :

.button:hover .initialText, .hoverText {
    display: none;
}
.button:hover .hoverText {
    display: block;
}

HTML:

<div class="button">
    <span class="initialText">Followed</span>
    <span class="hoverText">Unfollow</span>
</div>
+1

All Articles