.off() trouble
.off() trouble
I'm having trouble with the .off() method:
$(document).on("click", ".npc", function(){
$("#body").append("<h3>Blah</h3>");
$(this).off("click");
});
I'm trying to unbind the click event from .npc class after it's been clicked on, but it continually appends to body.
I've also tried this:
$(".npc").on("click", function(){
$("#body").append("<h3>Blah</h3>");
$(this).off("click");
});
In this case it's not appending at all. Maybe because the .npc class doesn't exist initially on page load?
Topic Participants
xenophone2
jakecigar