Prevent the div from being selected when it is behind the overlay

I am trying to display an overlay on top of a div. Once the overlay is displayed, I want to prevent any interaction with the background div. Unfortunately, when I double click on the overlay, the background div becomes selectable. Could someone please investigate this issue? Here is the link to the code snippet.

Answer №1

Solution

To achieve this effect, utilize the user select rules available in CSS and apply a specific class to the background element when activating the overlay:

CSS:

.unselectable { 
-moz-user-select: -moz-none;
   -khtml-user-select: none;
   -webkit-user-select: none;
   -ms-user-select: none;
   user-select: none;
}

Apply the class using jQuery:

$('#backgrounddiv').addClass('unselectable');

JSFiddle Example:

References:

Answer №2

$(document).ready(function() {
    $('#search_input').on('keyup',
    function() {
        user_input = $(this).val();
        $("#user_list li:contains('" + user_input + "')").addClass('active').siblings().removeClass('active');
    });
});

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

Autocomplete feature in Twitter's typeahead functionality for dynamically included input fields

I have successfully implemented Twitter typeahead on my website, but I am facing an issue when trying to dynamically add new input fields. What could be causing this problem? Thank you in advance for your responses. var custom = new Bloodhound({ ...

Move the cursor to the bottom of a div that can be edited

I have been struggling to position the cursor at the end of the next or previous editable content tag if the current one is empty. However, when I try to set focus, it always ends up at the beginning of the text instead of the end. I've tried various ...

Data cannot be found when jQuery form submission is attempted

I am facing a challenge with my webpage that generates multiple dynamic forms through a database, each intended to submit data to a webhook for an API call. Despite searching various forums extensively, I have not yet found a solution to my problem. It ha ...

The sudden disappearance of the vertical scrollbar in an absolutely positioned element

UPDATE : Added link to the example: http://jsfiddle.net/bfNzH/1/ This is how my HTML structure looks: <body> <div class="wrapper"> <div class="left">left bar</div> <div class="right"> < ...

Tips for receiving user input with custom values and assigning them to variables through multiple selection criteria using Jquery

I am encountering an issue with a form that contains multiple selection blocks. I am attempting to extract the values of each block criteria on click in order to send it to a database. However, every time I click on a block, my script retrieves all the val ...

Design elements using CSS within the <th> tags

When working with HTML tables, the use of a <th> element allows for the implementation of a scope attribute. This attribute serves to indicate whether the header cell is associated with its subsequent column, row, or group. Is it feasible to leverage ...

The reason why the div appears below the image

Is there a way to position the div above the image rather than below it, even when setting the z-index attribute in the code? The current code structure is as follows: <main id="content" role="main"> <div style="text-align: center"> & ...

What is the best way to align text in the center of a div?

I just created this dropdown menu, but I am encountering an issue. Whenever I resize the div or h4 element, the text ends up at the top. Even after trying to solve it with text-align: center;, the problem persists. Here is a visual representation of what ...

Height set at 100% but not extending to the entire parent element

I've applied min-height: 100vh; to the body, and then height: 100% to the main element. However, the height of the main does not extend fully to its parent container. Could someone please help me understand why this is happening? Thank you. I'v ...

The CSS float puzzle - text alignment dilemma

Recently, I created a simple float-based banner with tiles which you can see here on jsfiddle. However, I encountered a major issue with centering text in each tile. My goal is to have all the "Sample text" content centered both horizontally and vertically ...

Problems with CSS text scrolling

We have a client who wants a marquee-style scrolling text banner, and I tried using CSS animations to achieve it. However, I encountered some quirks that I'm struggling to fix. If you want to take a look at the issue, here is the link: https://jsfidd ...

How do I create a Bootstrap 4 multi-level navigation bar that drops to the right on the third level?

clickable dropdown hover dropdown.jpg Source: Is there a way to create a dropdown menu that opens to the right like the clickable version, rather than to the left like the hover dropdown in the provided example? I'm open to other solutions as long ...

Customize images using React JS to add an overlay on top of an HTML img

I'm looking to achieve a similar effect to Facebook where hovering over an image tag triggers a little overlay asking if you want to edit the photo. I have the hover functionality working, but I'm unsure how to implement the overlay. The image is ...

Is there a way to ensure that clicking a link_to only opens a partial once?

These are the files I am working with: _comment.haml %div.comment{ :id => "comment-#{comment.id}" } %hr - if current_user && current_user.id == comment.user_id || current_user && current_user.id == reel_user = link_to " ...

The webpage does not display the updated information from the controller after the Ajax call

Learning the ropes of MVC, I delved into creating a post method for showcasing fresh data post a datepicker selection in jquery. The jquery functionality is up and running smoothly, allowing me to iterate through the new data in the view. However, when i ...

Animate owlCarousel slide motion in reverse when using the Prev and Next buttons

The default functionality of owlCarousel is to move to the right when clicking Next and to the left when clicking Prev. However, after applying animations, both directions always move in the same direction. Check out this sample on jsfiddle to see the iss ...

Using JQuery to send an ajax DELETE request with data parameters

Is it possible to use data parameters in a DELETE ajax request with JQuery 1.8 or 1.7.2, for example: $.ajax({ url: '/config/delete', type: 'DELETE', data: {id:'blah'} } If this is not supported, one workaround c ...

Problem with scrolling horizontally through images using the <ul> and <li> tags

I am attempting to achieve a horizontal scrolling effect for a series of images, similar to what is shown in this example. I am facing an issue where the images do not align in a single row and instead move to the next line. How can I create horizontal scr ...

Maximizing Efficiency with Single Click Line Editing in the Newest Version of jqgrid

There seems to be an issue with single click inline row editing in the latest free jqgrid from github master. BeforeSelectRow, clicking on a row to start inline editing causes an exception: Uncaught TypeError: Cannot read property 'rows' of unde ...

Utilizing Bootstrap 4's nesting feature for optimal layout on an iPad in landscape

My nested content is functioning properly on all screen sizes except for ipad-landscape. Wouldn't it make more sense for the class triggered on ipad-landscape to be col-sm instead of col-lg? <div class="row"> <div class="col-lg-3 col-sm- ...