I wonder if you are having the flicker problem because of the difference in the parent div height once you hover over the child. I don't see your CSS so I can't tell for sure. One way to avoid this problem is to change it's visibility. Using display:none
will hide the element so that it will not take up it's original space. Using visibility:hidden
hides the content but leaves the original space of the object... I threw together some sample code using unobstrusive jQuery and a confirmation dialog box.
Notes
- The row id to delete is contained in the
name
attribute of the parent class.
- The parent div has the class name of
deleteme
, as IDs must be unique.
- If the Delete link takes up too much space, you can replace the child
div
with a span
to keep it inline.
HTML
<div class="deleteme" name="cid001">
Hover over me #1 (comment id=cid001)
<div> [X] Delete?</div>
</div>
<div class="deleteme" name="cid002">
Hover over me #2 (comment id=cid002)
<div> [X] Delete?</div>
</div>
Script
$(document).ready(function(){
$('.deleteme').hover(function(){
$(this).find('div').css('visibility','visible')
},function(){
$(this).find('div').css('visibility','hidden');
});
$('.deleteme div')
.css('visibility','hidden')
.click(function(){
// Confirmation
if (confirm("Are you sure?")){
alert( "delete row with ID = " + $(this).parent().attr('name') ); // the name contains the comment ID to delete
}
})
})