Hi i did some search about some function that i need , and i found it here on StackOverFlow . The problem is in all browsers i get "bug" on the script that says :
mouse_is_inside is not defined
But its defined ,and the function working perfect, and can't get rid from that message any advance?
I tryed though of that . but i dont know how to assume :
if (typeof variable === 'undefined') {
// variable is undefined
}
My function :
$(document).ready(function()
{
$('#contactbox').hover(function(){
mouse_is_inside=true;
}, function(){
mouse_is_inside=false;
});
$("body").mouseup(function(){
if(! mouse_is_inside) // the problem is here says not defined .
{
if ($.browser.msie && parseInt($.browser.version, 10) === 7) {
$("#main").css('z-index','0');
}
$('#contactb a').removeClass('cactive');
$('#contactb a').addClass('cnoactive');
$('#contactbox').hide()
}
});
});
EDIT thanks my bad , didnt know its so easy . i will tick the answer.
2 Answers 2
All you need is to add this line:
var mouse_is_inside = false;
...just inside the function. E.g.:
$(document).ready(function()
{
var mouse_is_inside = false;
// ...the rest of the code
});
Because the error is correct: You haven't defined it anywhere. But then the first time you do this:
mouse_is_inside=false;
or this:
mouse_is_inside=true;
...you're defining it, by falling prey to The Horror of Implicit Globals. In JavaScript's "loose" mode (the default), if you try to read the value of an undefined symbol, it's a ReferenceError; but if you write to an undefined symbol, it creates a global variable (implicitly). Fortunately, as of ES5, we have "strict" mode which makes both operations the errors they should be.
3 Comments
blarg but type blagr by mistake).Add declaration of mouse_is_inside i.e.
$(document).ready(function () {
var mouse_is_inside;
$('#contactbox').hover(function () {
mouse_is_inside = true;
}, function () {
mouse_is_inside = false;
});
$("body").mouseup(function () {
if (!mouse_is_inside) // the problem is here says not defined .
{
if ($.browser.msie && parseInt($.browser.version, 10) === 7) {
$("#main").css('z-index', '0');
}
$('#contactb a').removeClass('cactive');
$('#contactb a').addClass('cnoactive');
$('#contactbox').hide()
}
});
});