I have a twitter bootstrap table with a button group in the last cell of each row.
I want these buttons appear only when user hovers over the row. and need click both edit and delete icons separately.
I have following scripts
html
<div class="nesting">
<a href="#" class="foo-class nesting-item"><span class="glyphicon glyphicon-folder-open" area-hidden="true"></span> Foo <span class="pencil glyphicon glyphicon-pencil"></span></a>
<div class="nestchild">
<a href="#" class="nesting-item"><span class="glyphicon glyphicon-chevron-right" area-hidden="true"></span> Bar<span class="pencil glyphicon glyphicon-pencil"></span></a>
<a href="#" class="nesting-item"><span class="glyphicon glyphicon-globe" area-hidden="true"></span> This is a link<span class="pencil glyphicon glyphicon-pencil"></span></a>
</div>
</div>
css
.foo-class { float:left; padding : 3px; width:300px; min-width:300px; }
.nesting span.pencil { float:right; }
.nestchild a { clear: both;display : block; }
.nesting { background-color:#ccc; width:300px;}
.nesting a {width:285px;}
.nesting a .pencil {display : none; }
.nestchild { margin-left : 15px; }
javascripts
$(document).ready(function(){
$('.nesting a').hover(function(){
$(this).children('span.pencil').css({'display' : 'inline-block'});
},function(){
$(this).children('span.pencil').css({'display' : 'none'});
});
});
see this demo
https://jsfiddle.net/lilan2/a82jzucc/
how can I develop this properly
3
Answers
I don’t know if I understand correctly what you want, but check out this fiddle.
You can hide pencil link on document ready or by css and then on div of class
nesting
firehover
event that showspencil
class link. On mouseleave eventhide
pencil
class link.Then insert click event on
pencil
class insidenesting
class div.PS: I haven’t find any delete button in your code, but it’s the same principal of inserting on click on
pencil
class.If you want to show only the pencil icon corresponding to row hover, you can use each function on every link inside div
nesting
classInstead you can use jquery to update edit and delete buttons in table row on mouse over show edit delete buttons
Refer updated fiddle https://jsfiddle.net/VaibhavD/6aehaxr6/2/embedded/result/
There is no need of a jQuery script for your case. You can do it simply with css.
Just add a
:hover
style in css