Accessing a variable in hover

In hover, the structure is


$("div.x2").hover(
   function(){
	var a = 1;},
   function(){
       alert(a);}
);

If I want to access a that was set in the mouseover part of this structure, or I want to change the value of a from the second function, do I have to create a global variable that can be accessed by both or is there a way to pass this variable back and forth between the two functions since they are both within the hover event?

I think I’d use .data() for that


$("div.x2").hover(
   function() {
	$(this).data('a', 1);
   },
   function() {
       alert( $(this).data('a') );
   }
);

Perfect, thanks. I appreciate it.