Ace
Ace

Reputation: 845

Mouseleave fires when mouse is inside span

I am making this plugin

HTML

<span class="item" data-item="first">
</span>
  <br><br>
<span class="item" data-item="second">
</span>
<br><br>
<span class="item" data-item="third">

Jquery

(function($){
  $.fn.myPlugin = function(){
     $(this).on('mouseleave', function(){  
          var item = $(this).attr('data-item');
          alert(item);           
      });    

    return this.each(function() {    
      for (var i = 1; i <= 2; i++) {
        $(this).append('<span class="act" title="active '+i+'">act'+i+'</span>');
      }   
    });
  };
})(jQuery);



$(document).ready(function() {
  $('.item').myPlugin();
});

The problem is when i hover between two dynamically created elements mouseleave fires even if i'm inside item class. Demo http://jsbin.com/IWutoQa/9/

Try moving mouse between act1&act2

Upvotes: 1

Views: 431

Answers (1)

lionheart98
lionheart98

Reputation: 968

This is because of the margin-left: 10px! Use padding-left: 10px instead and it will work properly.

Example: jsfiddle

Upvotes: 3

Related Questions