I am getting unexpected results with jQuery trying to set the \"click\" method of a div. Please see this jsfiddle. Be sure to open the console window. Click the word a few times
Most likely you are running toggleDiv
mutliple times, resulting in the click event being bound multiple times. Bind the click event outside of the toggleDiv
function.
var status = false;
function toggleDiv()
{
console.log("toggleDiv(" + status + ")");
if (status) {
$("#test").html("Goodbye");
}
else {
$("#test").html("Hello");
}
status = !status;
}
$("#test").click(function() {
toggleDiv(status);
});