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()
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 ?