Steps to Show an Image When Hovering and Clicking on the Relevant 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;
}

Is there a way to implement the same functionality using jQuery instead?

Answer №1

$(document).ready(function () {
    $(".btn-small").click(function () {
        $('.imgFCheck').fadeOut();
        $(this).find('.imgFCheck').fadeIn();
    });
});

Answer №2

UPDATE:

Based on the additional information provided, it seems like this is what you'll require:

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


$(".btn-small").click(function(){
    $(".imgECheck").removeClass("show");
    $(".imgFCheck").addClass("show");
});

Answer №3

Give this code snippet a go


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

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

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

  });

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

});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Techniques for ensuring input validity using JavaScript

One of my form inputs is required: <input type="text" id="input-id" required> After the user submits it, I send the value using ajax and then clear it with $("#input-id").val(""). However, after this action, the input appears invalid. I want to ...

Place the sorting image on the left side of the DataTable header

I am currently using DataTable in my code. The sorting images in the header of the table are on the right side while the labels are on the left, as shown below: https://i.sstatic.net/Bz6EO.jpg However, I would like to switch this arrangement and have the ...

Unexpected data being passed in knockout click event binding

for (let i = 0; i < 9; i++) { vm.icdCodes.push({Index:i, ID:'',DiagnosisCd: '' ,Description:ko.observable('')}); } <tbody data-bind='foreach: $root.icdCodes'> <tr> <td> ...

Fetching data from local JSON file is being initiated twice

I need some help understanding why my code is downloading two copies of a locally generated JSON file. Here is the code snippet in question: function downloadJson(data, name) { let dataStr = 'data:text/json;charset=utf-8,' + encodeURICompo ...

Update the div using jq_form_remote_tag

Take a look below to see two images depicting a problem. The code snippet in my template, courtesy of j0k: <div id="listdiv"> echo jq_form_remote_tag(array( 'update' => 'listdiv', 'url' => 'shoppingl ...

Learn how to efficiently transfer a dynamic subtitle text value from an HTML5 video player to a database

I have successfully developed an HTML5 video player with subtitles. Currently, my goal is to allow the user to submit the subtitle text at a specific timestamp to a database. Despite trying various methods, I am facing challenges in fetching the subtitle t ...

Is it possible that the passing of Form Serialize and list to the controller is not functioning properly?

i am struggling with the following code in my controller: public ActionResult SaveWorkOrder(DTO_WorkOrder objWork, List<DTO_PartsWO> listTry) { //something } here is my model : public class DTO_WorkOrder { public string Id { get; set; ...

The spinal cord of design inquiry

I am currently working on a Backbone view called MainMenuView. Within this, the MainMenuModel consists of an array of sub-models known as ItemModel. The main menu is divided into two pages and includes next and previous buttons for navigation. The first pa ...

Utilizing jQuery to remove a class with an Ajax request

My setup includes two cards, one for entering a postcode and another with radio buttons to select student status (initially hidden). An Ajax request validates the postcode input - turning the card green if valid (card--success) and revealing the student se ...

Having trouble getting Javascript to reveal hidden elements based on their class

I am having some trouble making specific fields in a form appear based on the selection made from a dropdown menu. Below is a simplified snippet of my code, which should change the display from 'none' to 'block'. Can you help me figure ...

How can you use jQuery to select and manipulate a wildcard href ID?

There are multiple links listed below: <a href="http://www.google.com" id="link01">Google</a> <a href="http://www.yahoo.com" id="link02">Yahoo</a> <a href="http://www.cnn.com" id="link03">CNN</a> <a href="http://www. ...

Error: CodeIgniter encountered an invalid argument for the foreach function. Please review the input

I've encountered some issues while working on a Codeigniter application -- I have created a function like this: function searchUnivtab() { $country = $this->input->post('countryKey'); $state = $this->input->post( ...

Ways to create a unique animation for reducing the width of a div in a specific direction?

Currently, I have managed to animate the decrease in width of a div element. However, it is currently decreasing from right to left, and I would like it to decrease from left to right instead. Can someone please provide guidance on how to achieve this? ...

Can AngularJS Filters be used to convert a number into a string, but not the other way around?

After researching Angular JS filters, I discovered that the number filter is used to format a number as a string. However, there doesn't seem to be a built-in filter for converting a string to a number. In an attempt to solve this issue, here is so ...

Having trouble with adding a listener or making @click work in VueJS?

Apologies for my limited experience with Vue. I am currently facing an issue where one of my click functions is not working as expected for multiple elements. The click event is properly triggered for the #app-icon element. However, the function is not be ...

I am struggling to get the pop-up to close using the current code. I suspect that the issue might be related to the variable I was previously using in WordPress. I have made changes but the pop-up

While delving deeper into the realm of Javascript, I encountered a stumbling block with a single popup intended for the main page of a WordPress website I am constructing. Despite my attempts to modify the code's variables, they seem unyielding. Surpr ...

What steps can I take to create a responsive jQuery UI buttonset?

I am currently facing a challenge with my web app (http://www.tntech.edu/cafe-menu.php) which is being iframed into a mobile application developed by ATT. The button sizes vary on different phone models, and I am seeking a solution to make them responsiv ...

When opening a dialog at the bottom of the page, the window will automatically scroll to the top

I'm encountering an issue with a page that has a width exceeding 100% (2000px). Whenever I click to display a dialog from a button located at the end of the horizontal page, the window automatically scrolls back to the beginning of the page before sho ...

The Navbar is not displaying the React Bootstrap 4 CSS module as intended

Having some trouble changing the color of my navbar. Is there a step I might be missing? Here's the component I'm trying to render: import React from 'react'; import { Nav, Navbar } from 'react-bootstrap'; import styles from ...

Manually adding or removing rows in a DataTable

I've been racking my brain over this issue since yesterday and nothing seems to be working. Here's the problem: I have a table that utilizes DataTables (datatables.net). It needs to be cleared of all rows programmatically and then new rows added ...