Inside a function, I've got:
var myType;
if ( $(this).is(".whatever") ){
myType = typeOne;
} else if ( $(this).is(".something") ){
myType = typeTwo;
}
This works fine. However, I want to turn this into a separate function that I can call, since I use it in several different places. The function I write is:
function setMyType(){
var myType;
if ( $(this).is(".whatever") ){
myType = typeOne;
} else if ( $(this).is(".something") ){
myType = typeTwo;
}
}
When I call setMyType() in my main function, the main function can't access myType. If I alert(myType) inside setMyType(), the alert contains the correct value. But the main function can't see that value.
It's a scope issue, but I'm not sure how to resolve it. I tried defining myType inside the main function and passing it to setMyType(). While setMyType() gets the value of myType from the main function just fine, it still doesn't return the changed value to the main function.