1
요소 위에 마우스를 가져 가면 이미 존재하는 div를 표시하려고합니다. 요소에 div와 일치하는 ID가 있습니다.복제 된 div (jQuery) 제거
복제 및 표시 부분은 호버에서 작동하지만 이미 복제 된 요소를 제거했습니다. 나는 다른 대답에서 언급 된 벽장을 보았지만 아마 틀리게 사용했다. 그래서 단순히 당신이 현재 요소 this
제거 내부 '#reply_' + id
을 찾습니다
$(this).find('#reply_' + id).remove();
:
$('.referer').hover(function() {
var id = $(this).attr('id')
$('#reply_' + id).clone().appendTo(this);
}, function() {
var id = $(this).attr('id')
$('#reply_' + id).closest(this).remove();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="reply_1">
First Post
</div>
<div id="reply_2">
Second Post
</div>
<div id="reply_3">
Third Post
</div>
<!--The id is the id of the quoted post-->
<p>
<span class="referer" id="1">Quoted Link (First Post)</span>