简体   繁体   中英

How to display an image when hover and clicked on the respective div

CSS:

.imgECheck {
    position: absolute;
    top: 0;
    right: 5px;
    width: 15px;
    height: 15px;
    display: none;
}
.imgFCheck {
    position: absolute;
    top: 0;
    right: 5px;
    width: 15px;
    height: 15px;
    display: none;
}

How can I achieve the function in the JQuery above.

EDIT:

So after more info here's what I think you need:

$(".btn-small").on("hover", function(){
    $(".imgECheck").addClass("show");
});


$(".btn-small").click(function(){
    $(".imgECheck").removeClass("show");
    $(".imgFCheck").addClass("show");
});
$(function () {
    $(".btn-small").on("click", function () {
       $('.imgFCheck').hide();
       $(this).find('.imgFCheck').show();
    });
});

Can you try bellow code

 $(function () {
    $('.imgFCheck').hide();

  $(document).on('click','.btn-small', function () {

    $(this).find('.imgFCheck').show().toggleClass('is-clicked');

  });

  $(document).on('hover','.btn-small', function () {
     if(!$(this).find('.imgFCheck').hasClass('is-clicked'))
      {
        $(this).find('.imgFCheck').toggle();
       }
   });

});

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