2017-07-09 4 views
-1

Here ist mein Code:Warum .remove() entfernt das Element nicht?

$(document).ready(function(){ 
    $('a').bind('mouseenter', function() { 
    var self = $(this); 
    this.iid = setTimeout(function() { 
     var tag_name = self.text(), 
      top  = self.position().top + self.outerHeight(true), 
      left  = self.position().left; 
     $('body').append("<div class='tag_info'>Some explanations about "+tag_name+"</div>"); 
     $(".tag_info").css({top: top + "px", left: left + "px"}).fadeIn(200); 
    }, 525); 
    }).bind('mouseleave', function(){ 
    if(this.iid){ 
     clearTimeout(this.iid) 
     remove($('.tag_info')); 
    } 
    }); 
}); 

Wie Sie in der Geige sehe ich zur Verfügung gestellt haben, wenn Sie mit der Maus den Tag verlässt, dass Black-Box ist noch vorhanden. Warum? Und wie kann ich es entfernen?

+2

Try '$ zu benutzen ('tag_info'). Remove()' – ThisGuyHasTwoThumbs

+0

, warum Sie nicht getan haben, dass mit ' : schweben? –

Antwort

6

Verwenden Sie stattdessen den folgenden Code.

$('.tag_info').remove(); 
2
remove($('.tag_info')); 

sollte in erster

$('.tag_info').remove(); 
0

in jQuery Selektor definieren sein.

$('.tag_info').remove(); 
1

$(document).ready(function(){ 
 
    $('a').bind('mouseenter', function() { 
 
    var self = $(this); 
 
    this.iid = setTimeout(function() { 
 
     var tag_name = self.text(), 
 
      top  = self.position().top + self.outerHeight(true), 
 
      left  = self.position().left; 
 
     $('body').append("<div class='tag_info'>Some explanations about "+tag_name+"</div>"); 
 
     $(".tag_info").css({top: top + "px", left: left + "px"}).fadeIn(200); 
 
    }, 525); 
 
    }).bind('mouseleave', function(){ 
 
    $('.tag_info').remove(); 
 
    }); 
 
});
body{ 
 
     padding: 20px; 
 
    } 
 

 
    a { 
 
     color: #3e6d8e !important; 
 
     background-color: #E1ECF4; 
 
     padding: 2px 5px; 
 
    } 
 
    .tag_info{ 
 
     position: absolute; 
 
     width: 130px; 
 
     height: 100px; 
 
     display:none; 
 
     background-color: black; 
 
     color: white; 
 
     padding: 10px; 
 
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
    <a>tag1</a> 
 
    <a>tag2</a>

check the code `https://jsfiddle.net/uz6y3L2y/3/` may help you. 
0

Du funciton remove() in falscher Weise mit Jquery, das ist, warum es die .tag_info Klasse hat nicht das Element zu entfernen. Bitte verwenden Sie es als pro documentation

remove($('.tag_info')); // Not Correct 

Sie benötigen es, wie diese

$('.tag_info').remove(); 
Verwandte Themen