Looking for a CSS selector equivalent to the $.fn.closest()
function, such as:
$('.wrapper:eq(0)>h1>strong:closest(.wrapper)')
The goal is to have the implementation return the .wrapper
element that is the first on the page, containing an h1
which in turn contains a strong
element.
While the example above serves illustrative purposes, in reality, I require $.fn.draggable
functionality to establish a dynamic containment
attribute.
UPDATE
To clarify further: there are multiple instances of div.wrapper
on the page, each following the other. These wrappers are connected as sortable areas with div.sub-wrapper
elements serving as sortable items placed over them. The items can be moved between wrappers. Each sortable item includes a child div
element, which acts as the draggable component. What I need is to set the draggable.options.containment
of this draggable element to its current parent wrapper. The challenge lies in updating the containment dynamically when moving the item from one wrapper to another.
{containment: $('div.draggable').closest('div.wrapper')}
Using the code above may not work correctly when shifting the div.sub-wrapper
to a different div.wrapper
, as the containment element remains linked to the initial wrapper.