How to access a variable outside a function in Javascript
Posted
by Luke101
on Stack Overflow
See other posts from Stack Overflow
or by Luke101
Published on 2010-04-30T19:04:56Z
Indexed on
2010/04/30
19:17 UTC
Read the original article
Hit count: 181
jQuery
|JavaScript
Here is the code I am working with:
$(document).ready(function () {
var TemplateEditor = function () {
var GroupClassName = 'group';
var SelectedGroup = 0;
var BindClicks = function () {
$('.CriteriaSelections').unbind('click').click(function (event) {
event.preventDefault();
if (fnIsTheClickedBoxaGroup($(this))) {
TemplateEditor.GroupClicked();
}
else {
TemplateEditor.CriteriaClicked($(this), SelectedGroup);
}
});
$('.groupselected').unbind('click').click(function (event) {
event.preventDefault();
SelectedGroup = $(this).attr('group-'.length);
TemplateEditor.SelectGroup(SelectedGroup);
});
}
var fnGetGroupID = function (Obj) {
if (fnIsTheClickedBoxaGroup(Obj) == true) {
return null;
}
else {
//Get parent which is the group
var ObjParent = Obj.parent();
var GID = ObjParent.attr('id').substr('group-'.length);
return GID;
}
}
var fnIsTheClickedBoxaGroup = function (Obj) {
var GetClass = Obj.attr('class');
if (GetClass == GroupClassName) {
return true;
}
else {
return false;
}
}
return {
Init: function () {
BindClicks();
},
CriteriaClicked: function (Obj, GroupID) {
$('<div>').attr({ id: '' }).addClass('selection').text(Obj).appendTo('#group-' + GroupID);
},
GroupClicked: function () {
},
SelectGroupClicked: function () {
},
UpdateTargetPanel: function () {
}
};
} ();
TemplateEditor.Init();
});
I am trying to access this variable: GroupClassName
This variable is inside this function
var fnIsTheClickedBoxaGroup = function (Obj) {
var GetClass = Obj.attr('class');
if (GetClass == GroupClassName) {
return true;
}
else {
return false;
}
}
When I run the program it says GroupClassName is undefined. Am I missing something here?
© Stack Overflow or respective owner