Allow only the modals that do not have a particular parent class to be dragged

I am currently working on making all the modals draggable on my website. However, there are certain modals with a class of .fullscreen that I do not want to be draggable.

The issue I'm facing is that I can't figure out how to exclude the modals with the .fullscreen class because they share the same parent element .modal-dialog.

Despite trying various selectors, I have been unsuccessful in achieving this.

const $modal = $('.modal');
$(".modal-dialog:not(.modal.fullscreen)", $modal).draggable({
     handle: '.modal-header'
}); 

<div id="employee-modal" class="modal fullscreen dark advanced-search show">
        <div class="modal-dialog">
            <div class="modal-content">
                ....
            </div>
        </div>
    </div>

Answer №1

Have you considered this approach:

const $modal = $('.modal:not(.fullscreen)');
$(".modal-dialog", $modal).draggable({
     handle: '.modal-header'
}); 

If the code above accurately depicts your intentions, it simply adjusts the selector to exclude fullscreen modals. If you plan to use $modal later on, you could revise it as follows:

const $modal = $('.modal');
$(".modal-dialog", $modal.filter(':not(.fullscreen)')).draggable({
     handle: '.modal-header'
}); 

The concept remains the same – excluding fullscreen modals from the context. However, for improved readability, consider storing non-fullscreen modals in a separate constant like

const nonFullScreenModals = $modal.filter(':not(.fullscreen)');

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

Entering a new row and sending information through ajax

I'm looking for some help with a web page I have that includes a particular table structure: **Check out my Table*:* <table id="staff" class="table"> <thead> <tr> <th>First Name</th> <th>Last Nam ...

Optimizing Safari for the Best Screen Size Experience

I seem to be encountering issues with optimizing my website. Everything appears to be working correctly in terms of widths, heights, margins, etc., on my laptop. However, when I view the site on an iMac or any other computer with a larger screen size, the ...

Extracting auto-populate suggestions from MySQL database

I am currently using a Jquery autosearch function that works well with hardcoded availableTags, but I would like to be able to select them from a database instead. <script> $(document).ready(function(){ $("#tabs").tabs(); var av ...

Is it possible to save jQuery plugin initialization settings for future use?

Is it possible to save a default set of settings for a lightbox jQuery plugin, including options and callback functions, in a variable or array that can be referenced later in different contexts with varying configurations? For example, could I initially ...

Troubleshooting the jQuery .load() issue across various versions of Internet Explorer

I am currently working on a dynamic template where I have links in the sidebar and I want to load content dynamically using .load() in jQuery. Below is the jQuery code I am using for this purpose: // Ajax page loader for services jQuery('.sidenav a ...

Create a custom implementation of Bootstrap's Typeahead feature using Angular, CSS, and HTML without relying on any pre-existing libraries

Is there a way to achieve bootstrap's typeahead suggestive hint feature using only angular, html, and css? I want to dynamically display the first item of the search results in the search box! <body> <div ng-app="demoApp" ng-controller=& ...

The next promise in a promise chain does not wait for the previous promise to resolve

I am completely new to the concept of Promises, but I have read that they are a powerful tool for executing functions one after another through Promise chaining. The code snippet below, under //RUN ON CLICK: CREATE TABLES, makes two AJAX calls - "Create D ...

Retrieving data with JQuery when encountering an XHR error

When I send a jQuery AJAX request and receive a successful response, I am able to retrieve my JSON data. However, if the response code is anything other than 200, I am unable to access the data in the jQuery callback function. This data is crucial as it co ...

jQuery Does Not Iterate Through Arrays

I am encountering an issue where I am trying to populate an array with images and then pass them to a variable called $image. However, when I attempt to iterate over this array, the same item is being alerted three times. Here is the problematic code snip ...

Arrangement of Div Box

Here is the HTML code that I am currently working with: <div class="item"> <div class="pageheader"> Header </div> <div class="info"> Created on... </div> <div class="image"> I ...

Expanding a centered div beyond 100% width will cause the div to only enlarge towards the right side

I am currently in the process of revamping the login page for my website. I am facing a challenge where I am unable to adjust a div element to extend beyond 100% without it overflowing to the right side instead of the left. Despite trying various methods, ...

Developing a website with all features and functionality using only traditional coding techniques

When I mention "Vanilla Coding", I mean websites that rely solely on HTML, JavaScript, and CSS without any server side coding like PHP or ASP. I've noticed there are many websites out there that seem to function perfectly fine without using common se ...

Having trouble with sending a form post and ajax post at the same time?

My coding skills may be lacking, but I am using a library called 'Croppie' to crop and post photos. The Croppie plugin is embedded in a form with additional data that also needs to be submitted, but unfortunately it is not working as expected. $ ...

Retrieve Data from HTML Table using jQuery

I am working with an HTML table that has the following values: <tr class="tuker1"> <td class="tuker-lft1"> Username </td> <td class="tuker-rght1" onclick="awardRoute()"> <a href="#"> AWARD ROUTE </ ...

Content descriptor with numerous lines

Currently, two things are on my mind... First: I'm attempting to set up a contact section with a few basic text input fields. One of these fields is meant for longer messages and should have multiple rows. The issue I'm facing is figuring o ...

What is the best way to ensure Bootstrap columns adapt to different screen sizes on all devices?

Seeking assistance with creating a responsive Login/Register page layout. At present, the desktop version appears like this on 1920x180: http://prntscr.com/cl4ms8 Utilizing <div class="col-xs-6"> for both forms to ensure equal division on the page. ...

Show information in a div when clicked using a data attribute that contains a secondary div with the same data attribute

I have 3 div elements, each containing a unique data attribute: <div class="box"> <div class="item" data-category="#music"> CLICK </div> </div> <div class="box"> <div class="item" data-category="#movies"> CLICK &l ...

Determine the aspect ratio of the image and incorporate it into the query string

In my current code, I am extracting the dimensions of an image obtained from a cropper tool. I then calculate the aspect ratio of the image by dividing the height by the width. This value is then incorporated into the query string url: urlLocation + imag ...

What's the best way to arrange a series of images in a horizontal line using html and css?

Looking for a way to display a list of images in a straight line with just the right amount of spacing between them? Check out my fiddle and see the challenge I'm facing. https://i.sstatic.net/ZvICc.png I've been experimenting with HTML c ...

Is it feasible to retrieve information within a behavior in Drupal?

I recently installed the "Autologout" Drupal module, which can be found at . This module includes a timer that ends your session if there is no activity on the page for a set period of time. However, I am interested in adjusting the timer value to better ...