Tips for reactivating a disabled mouseover event in jQuery

I created an input field with a hover effect that reveals an edit button upon mouseover. After clicking the button, I disabled the hover event using jQuery. However, I am unable to re-enable this hover event by clicking the same button.

Here is the code snippet:

$('#Organaization_Desg_modal_view_Desg_input_hover1').mouseover(function () {
        $('#Organaization_Desg_view_modal_desg_name_edit_icon1').show();
    });
    $('#Organaization_Desg_modal_view_Desg_input_hover1').mouseout(function () {
        $('#Organaization_Desg_view_modal_desg_name_edit_icon1').hide();
    });
    
    
    
    $('#Organaization_Desg_view_modal_desg_name_edit_icon1').click(function () {
    $('#view_modal_edit_desg_name1').prop('disabled', false);
    $('#save_view_desg_name1').show();
                          $('#Organaization_Desg_modal_view_Desg_input_hover1').off("mouseover");    //disables the mouseover event
    });
    
    
    $('#save_view_desg_name1').click(function () {    // save changes to input field
        $("#view_modal_edit_desg_name1").prop('disabled', true);
        $('#save_view_desg_name1').hide();
        
        $('#Organaization_Desg_modal_view_Desg_input_hover1').on("mouseover");   // this part of code is not working
    });
.hide{
display:none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="Organaization_Desg_modal_view_Desg_input_hover1">
<input type="text" id="view_modal_edit_desg_name1" class="Organaization_Desg_input_box " disabled value="Public Relationship Officer" />

<button id="Organaization_Desg_view_modal_desg_name_edit_icon1" class="hide">click to disable mouseover</button>
</div>

<button id="save_view_desg_name1" class="hide"> click to enable mouseover</button>

Answer №1

To simplify this code, you can incorporate the mouseover and mouseout functions along with the

$('#save_view_desg_name1').click(function () {

$('#Organaization_Desg_modal_view_Desg_input_hover1').mouseover(function () {
    $('#Organaization_Desg_view_modal_desg_name_edit_icon1').show();
});
$('#Organaization_Desg_modal_view_Desg_input_hover1').mouseout(function () {
    $('#Organaization_Desg_view_modal_desg_name_edit_icon1').hide();
});

$('#Organaization_Desg_view_modal_desg_name_edit_icon1').click(function () {
    $('#view_modal_edit_desg_name1').prop('disabled', false);
    $('#save_view_desg_name1').show();
    $('#Organaization_Desg_modal_view_Desg_input_hover1').off("mouseover"); //disables the mouseover event
});

$('#save_view_desg_name1').click(function () { // save changes to input field
    $("#view_modal_edit_desg_name1").prop('disabled', true);
    $('#save_view_desg_name1').hide();$('#Organaization_Desg_modal_view_Desg_input_hover1').mouseover(function () {
        $('#Organaization_Desg_view_modal_desg_name_edit_icon1').show();
    });
    $('#Organaization_Desg_modal_view_Desg_input_hover1').mouseout(function () {
        $('#Organaization_Desg_view_modal_desg_name_edit_icon1').hide();
    });
    
    // The next section of code is currently not functioning as intended
    // $('#Organaization_Desg_modal_view_Desg_input_hover1').on("mouseover");
});
    
    
    
    
.hide{
    display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="Organaization_Desg_modal_view_Desg_input_hover1">
    <input
        type="text"
        id="view_modal_edit_desg_name1"
        class="Organaization_Desg_input_box"
        disabled
        value="Public Relationship Officer" />
    <button
        id="Organaization_Desg_view_modal_desg_name_edit_icon1"
        class="hide">
        click to disable mouseover
    </button>
</div>

<button id="save_view_desg_name1" class="hide">
    click to enable mouseover
</button>

Answer №2

A more efficient approach is to utilize the "readonly" attribute of the input element instead of disabling mouseover events.

$(function(){
  $('.disable').click(function(){
    $(this).siblings('.example-input').attr("readonly", true);
    $(this).siblings('.enable').css("visibility","visible");
    $(this).parent().find('button.disable').css("visibility","hidden");
  });
  $('.enable').click(function(){
    $(this).siblings('.example-input').attr("readonly", false);
    $(this).siblings('.disable').css("visibility","visible");
    $(this).parent().find('button.enable').css("visibility","hidden");
  });
});
.example > .disable{
  visibility: hidden;
}
.example:hover > .disable{
  visibility: visible;
}
.enable{
  visibility: hidden;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="example">
  <input type="text" class="example-input"/>
  <button type="button" class="example-button disable">Click to disable</button>
  <button type="button" class="example-button enable">Click to enable</button>
</div>

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

Selenium Tips: Ensuring RemoteDriver Remains Connected to the Active Browser Tab

Currently working on a unique Windows application that utilizes voice commands to control web browsers. I am trying to figure out the best approach when users add tabs and modify the selected tab as needed. Unfortunately, RemoteDriver only supports swi ...

Tips on transforming a JavaScript function constructor into TypeScript

Transitioning from JavaScript to TypeScript has presented me with some challenges. One of the tasks I need to accomplish is converting a constructor function into its TypeScript equivalent. The original JavaScript function looks like this: export default ...

Limiting the data obtained from the API to extract only the desired values

Using an API, I am retrieving customer information and displaying it in the console. The code snippet used for this operation is: if (this.readyState === 4) { console.log('Body:', this.responseText); } }; This returns a JSON object with v ...

Creating a perpetual loop animation for two divs moving from right to left endlessly

Here is the code I have: HTML <div class="screen screen1"></div> <div class="screen screen2"></div> CSS .screen{ width: 100%; height: 50%; position: absolute; background-color:#001; background-image: radial- ...

Retrieve various URLs within an object using React

My task involves extracting all URLs from a specific object. Object { "Info": "/api/2", "Logo": "/api/2/Logo", "Photo": "/api/2/photo", } I aim to store the responses in a state, ensuring t ...

Struggling to filter an Array within an Array based on dates falling between a specific date range

Currently, I am using a filtering method that is working perfectly, but I am facing an issue where I lose my original Array when there are no dates between the specified range (as expected). Is there a way to prevent this data loss? The reason I need to r ...

What is the best way to transform Adobe XD designs into HTML and CSS with Vue.js?

I am looking to create a single page application with vue.js and came across this helpful reference at . A colleague has created a prototype using Adobe XD, and now my task is to transform it into HTML/CSS while making it functional and connecting it to an ...

Combining various API requests within a Vue component, which includes a for loop

I'm delving into the world of API chaining, specifically trying to link two different API calls within a 'notes' Vue component. My knowledge of promises is basic at best, but I'm eager to enhance my skills in this area. The initial API ...

Adjusting the Underline Navigation Effect with jQuery

My current setup includes a basic navbar with an up arrow that slides underneath it when a navigation title is clicked. The arrow initially rests between two nav titles, and when one of them is clicked, some text also slides in. I am looking to implement ...

Extracting text from HTML elements using BeautifulSoup

I'm working with the following html code and I want to extract the text that comes after <b>Name in Thai</b>, specifically : this is what I want content = """ <html><body><b>Name of Bangkok Bus station:</b> <spa ...

NPM Datatable Excel export button not appearing

My Excel Button in the data table is not showing up. I've imported all scripts using NPM, and all other buttons work perfectly fine (like PDF, Copy, Print). But specifically, the Excel button doesn't seem to be working. Here are my imports: imp ...

Avoid changing the regex pattern if it is surrounded by a specific character

I want to change all occurrences of strings enclosed by - with strings enclosed by ~, unless the string is again surrounded by *. For instance, consider this string... The -quick- *brown -f-ox* jumps. ...should be altered to... The ~quick~ *brown -f-ox ...

How to change the color of a row in Jquery selectize using its unique identifier

Is it possible to assign different row colors for each value in the jquery selectize plugin? I would like to set the row color to green if the ID is 1 and red if the ID is 0. This is my selectized field: var $select = $('#create_site').selecti ...

Did you manage to discover a foolproof method for the `filesystem:` URL protocol?

The article on hacks.mozilla.com discussing the FileSystem API highlights an interesting capability not previously mentioned. The specification introduces a new filesystem: URL scheme, enabling the loading of file contents stored using the FileSystem API. ...

Transform the size and convert an object from a picture into text based on the user's scrolling

I've been intrigued by the scrolling effects used on websites like Google SketchUp and Google Plus. It's fascinating how elements can transform as you scroll down the page. For example, on Google SketchUp's site, the banner starts off integr ...

strange occurrences in localToWorld transformation

Hello there! Currently, I'm working on a project where I'm generating a TextMesh using font geometry and placing it within an empty pivot object. My goal is to obtain the world coordinates of each vertex in the TextMesh so that I can manipulate ...

Merging two arrays that have identical structures

I am working on a new feature that involves extracting blacklist terms from a JSON file using a service. @Injectable() export class BlacklistService { private readonly BLACKLIST_FOLDER = './assets/data/web-blacklist'; private readonly blackl ...

How to Delete the Bottom Border on Selected Tabs in MUI Using React

I am attempting to customize the appearance of MUI Tabs to achieve a design similar to the image below: https://i.sstatic.net/tBS1K.png I have created a sample code example in a codesandbox environment. You can view it here: Codesandbox Example. In this e ...

Ensuring accurate data entry through form validation within a table format

I'm working with a textbox that is part of a table column. My goal is to make sure the entire column is not empty when the Ok button is clicked. If you have any suggestions on how I can achieve this, please let me know. var formatTableMandatoryVa ...

Using JQuery toggleclass to add transitioning effects to a :after element

I'm using the toggleClass function to add the class .expend to a div with an ID of #menu, which increases the height of the menu from 100px to 200px with a smooth transition effect. I also have a pseudo-element #menu:after for aesthetic purposes. My ...