What is the method for ensuring that the delete functionality is displayed within the same row?

In my division, there are options for names and deletion. It is displayed on my website as:

1.jpg delete

The HTML code for the division is:

<div id="files1" class="files">
     <b class='dataname' >1.jpg</b>
     <span class='delimg' >delete</span>
 </div>;

The CSS code for the delimg class is:

.delimg{
    margin-left:20px; 
    color:#090;
    cursor:pointer
 }

I initially want the delete option to be hidden, so I added display:none in the delimg CSS:

.delimg{
    margin-left:20px;
    color:#090; 
    cursor:pointer; 
    display:none
 }

Therefore, when hovering over the name 1.jpg, the delete should appear; and disappear when moving away from the name. I attempted to achieve this using the hover function:

$(document).ready(function() {
    $('.files').hover(function() {
         $('.delimg').css("display","block");
    });
});

However, the positioning of the delete changed to underneath the name 1.jpg instead of beside it, like this:

1.jpg
 delete

Additionally, I noticed that even after moving my mouse off the name, the delete option remained visible. This occurred because the delimg's display attribute was set to block, causing it to persist. I attempted using both mouseover and mouseout methods. The delete would appear when hovered over, but clicking on it became difficult, as it disappeared immediately upon moving the mouse away from the name.

Answer №1

Instead of relying on Javascript, you can achieve this using CSS alone:

.files:hover .delimg{
    display: inline-block;
}

The reason the element appears below is because you are using block instead of inline-block. Check out this functional example:

.delimg {
    margin-left:20px;
    color:#090; 
    cursor:pointer; 
    display:none
}
 
.files:hover .delimg {
    display: inline-block;
}
<div id="files1" class="files">
     <b class='dataname' >1.jpg</b>
     <span class='delimg' >delete</span>
 </div>
 <div id="files2" class="files">
     <b class='dataname' >2.jpg</b>
     <span class='delimg' >delete</span>
 </div>

Answer №2

To revert the default display property of the delete span, consider using this alternative approach and apply display:none on mouseout.

$(document).ready(function(){
$('.files').mouseover(function(){
$('.delimg').css("display","unset");
});
 $('.files').mouseout(function(){
    $('.delimg').css("display","none");
});

}); Feel free to reach out if this resolves your issue.

Answer №3

It appears that you are facing two issues :

  1. One problem is that the delete link remains visible even when the mouse moves away.

    To resolve this, consider utilizing the jquery toggle method within your code:

    $('.delimg').css("display","block");
    This way, the display: block property will toggle back and be removed, allowing the link to hide on mouseout.

  2. The second issue is that the delete link appears below the jpg on a new line. To fix this, use the display: inline-block property instead of display: block in both your CSS file and event callback method.

Alternatively, you can achieve all of these changes using only CSS as suggested by other answers.

We hope this response addresses your concerns.

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

Update the image source within a CSS element

I'm facing an issue with changing the source image of an Element. The situation is that I have a customized CSS script and I need to modify a logo image. Below, you can find the source code: https://i.stack.imgur.com/8HLCE.png The problem lies in at ...

Manage shared nested modules across different modules in Vuex without redundancy

In my Vue.js application, I am using Vuex as the state manager. To ensure that certain states are shared across different components, I have created a nested state containing all the common information. This allows me to import it into multiple modules. F ...

Steps for designing a stationary footer in HTML and CSS

I have implemented a static footer on my website: HTML <div class="card fixedFooter"> <div class="card-body space-around"> <button type="button" class="buttonFooter" routerLink="/myRouter" > <i class ...

different ways to dynamically increase CSS ID in PHP

Is there a way to dynamically increment my CSS ID using PHP? foreach ($query_cat->result() as $row_cat) { $row_cat_id = $row_cat->id; echo '<div class="product-wrapper">'; echo '<div id="product-header' . $r ...

Capture all parameters in the URL, regardless of their names

Hello, I am currently utilizing the s:url tag to create a URL in my JSP file for pagination purposes. The issue I am facing is that when clicking on the previous link, it generates a URL in the address bar like someAction?previuos=prev. Similarly, when cli ...

Update the icon class for the Kendo Date Picker using jQuery

Looking to implement the kendo Jquery Date Picker feature but encountering some issues. I've been consulting https://docs.telerik.com/kendo-ui/controls/editors/datepicker/overview.html for guidance. Instead of the default k-i-calendar class, I' ...

How to disable the underline styling for autocomplete in a React Material UI component

Seeking assistance with removing underline styling and changing text color upon focus within the autocomplete component of React Material UI. Struggling to locate the specific style needing modification. Appreciate any help in advance! ...

A distinct handler function designed for a dynamically generated form

I have 3 MaterialUI TextFields that are rendered n number of times based on user input (stored in a variable named groupMembersCount) in a functional ReactJS component using the useState hook: const [groupDetails, setGroupDetails] = React.useState([ { ...

Custom sparkline array

In working on my sparkline chart, I have the following code snippet: <div sparkline="" values="4,4,7,5,9,6,4" data-type="line" data-height="80" data-width="100%" data-line-width="2" data-line-color="#dddddd" data-spot-color="#bbbbbb" data-fill-c ...

Executing a prop function within the useEffect hook: a step-by-step guide

I am attempting to address this warning in a react component Line 19:8: React Hook useEffect has a missing dependency: 'handleChange'. Either include it or remove the dependency array react-hooks/exhaustive-deps This is the component: ...

Develop a loading modal for all AJAX requests, with the exception of a specific one

I've implemented a code snippet to display a modal for ajax requests: $(document).ajaxStart(function () { showLoadingModal(); }); $(document).ajaxError(function () { closeLoadingModal(); alert("error"); }); Although this code creates a modal ...

Transforming FormData string key names into a Json Object that is easily accessible

Recently, I encountered an issue where my frontend (JS) was sending a request to my backend (Node Typescript) using FormData, which included images. Here is an example of how the data was being sent: https://i.stack.imgur.com/5uARo.png Upon logging the r ...

Maintaining the relative position of an SVG while scaling within a div element

I am in the process of incorporating my custom SVG knob icons into an electron application using flexbox. The challenge lies in keeping them centered within the rectangle icon regardless of browser size, as shown here. Ideally, the icons should adjust thei ...

The message sent back by Django Rest Framework is: "a legitimate integer must be provided"

I have integrated a react form within my Django application, supported by the rest framework in the backend. When I submit the form without entering any value in the integer field, I encounter the following error message from the rest API: "a valid integer ...

Creating a JavaScript/jQuery array containing values from multiple input fields

Having trouble figuring out a simple question. I want to create a JavaScript array of input values, but can't seem to get the code right. Below is the HTML: <input class="email" value="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" ...

"Unleashing the Glamour: Tips for Decorating an Amazing Ajax Pop

I need help styling a magnific pop-up that displays content from a uri. The content is just plain text and I want to avoid using any html code as the popup will be triggered by a button. The current code I have written functions correctly, but the appeara ...

Chakra UI: How come the tooltip is appearing in the top left corner of the screen instead of directly above the element?

CreatedByModal is a unique chakra modal that incorporates tooltips. However, I am facing an issue where the tooltip appears at the top of the screen instead of directly above the icon when hovering over the icons. You can see in the image provided that the ...

Obtaining the value of a checkbox with React

I have a form with two input fields (email, password) and a checkbox. The code for the form is shown below: <Box component="form" onSubmit={handleSubmit} noValidate sx={{ mt: 1 }}> <TextField margin="normal" required ...

When viewing HTML "Div" on smaller screens, the full height may not be displayed properly

My setup includes two monitors: one is 24" and the other is my laptop's 12.5" screen. I have a red box (div) in my web application that displays full height on the larger monitor, but only partially on the smaller one. I'm puzzled as to why it s ...

Sending comprehensive information from a Spring Boot server to a client via Web Socket

I have a spring boot server and I'm able to create a streaming table on the client side by sending JSON data consecutively. However, there is an issue where a user who logs in after 10 minutes can only access data from the 10th minute onwards, missing ...