How can I use a variable outside of a click() in jQuery? I have the following code –
$(".area").not(".enemy").click(function(){
$(".area").removeClass("clicked");
$(this).toggleClass("clicked");
attackValue = $(this).text();
});
When I want to use attackValue outside of the click() It will not be defined.
In order to keep attackValue defined outside of the scope of the function, you will need to declare it outside of your click event.
Now you should be able to reference it outside.