Shihab Mian
Shihab Mian

Reputation: 15

$(selector).mouseenter() Beginner

$('window').mouseenter(function(){
    mouseover = true;
}).mouseleave(function(){
    mouseover = false;
});

In the code above, would 'window' be correct syntax? If not, what would be the correct way to create a Boolean that tracks when the mouse in on the window and then off the window.

Upvotes: 1

Views: 36

Answers (2)

Scarecrow
Scarecrow

Reputation: 4137

In Javascript window is an object, so your code will be

var mouseover;
$(window).mouseenter(function(){
  mouseover = true;
}).mouseleave(function(){
  mouseover = false;
});

Upvotes: 0

11thdimension
11thdimension

Reputation: 10633

Following is correct syntax

$(window).mouseenter(function(){
    mouseover = true;
}).mouseleave(function(){
    mouseover = false;
});

$('window') will try to look for a tag named window, not the window object.

Upvotes: 1

Related Questions