简体   繁体   中英

Is there an easier way to show/hide an element on a mouse action?

I have this segment of code here, which I seem to use something similar all the time:

$(".fieldv").live('mouseenter', function() {
    $(this).children('.edit-icon').show();
}).live('mouseleave', function() {
    $(this).children('.edit-icon').hide();
});

Is there an easier, simpler, or cleaner way to show / hide an element on a mouse action whether it be hovering or clicking an element? Or something of the like...

Why use JavaScript?

You will need to hide the icon by default:

.fieldv .edit-icon { display: none; }

Then this CSS applies on hover (and ONLY on hover)

.fieldv:hover .edit-icon { display: block; /* or inline, etc. */ }

You could try this:

       $(".fieldv").hover(function(){

              //mouseover

       ,function(){

              //mouseout
       });
$(".fieldv").hover(function() {
        $(this).children('.edit-icon').show();
    }, function() {
        $(this).children('.edit-icon').hide();
 });

use $(".class").hover(function(){}, function(){});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM