How to get global variable in JQuery functions
- by Tahir Akram
I want to access my global javascript variable in JQuery methods. But I am unable to get it when I go to attach a click even to a div. As following.
How can I do that? I mean do I need to rely on hidden fields for some state management?
var divCount = 3;
$(function() {
//divCount is accessible here
$("#sortable").sortable({
revert: true
});
$("#new").click(function(){
if (divCount<7){
//divCount is not accessible here. why? and how?
var thisCount = ++divCount;
$("#draggable_"+thisCount).addClass("draggable");
}
});
});