How can I set "DOP_ThumbnailGallery_Container" to have the width of the parent container
$('.DOP_ThumbnailGallery_Container', Container).width($(Container).width());
I tried this way /\ but it doesn't work, it gives the width of the window;
I even tried to have the outer container with overflow hidden, but it breaks it!
To get the parent height and width in React: Set the ref prop on the element. In the useEffect hook, update the state variables for the height and width. Use the offsetHeight and offsetWidth properties to get the height and width of the element.
jQuery width() Method The width() method sets or returns the width of the selected elements. When this method is used to return width, it returns the width of the FIRST matched element. When this method is used to set width, it sets the width of ALL matched elements.
The solution is to simply not declare width: 100% . The default is width: auto , which for block-level elements (such as div ), will take the "full space" available anyway (different to how width: 100% does it).
The parent() method returns the direct parent element of the selected element. The DOM tree: This method only traverse a single level up the DOM tree. To traverse all the way up to the document's root element (to return grandparents or other ancestors), use the parents() or the parentsUntil() method.
Have you looked at the parents function of jquery?
You can do something like this:
$('.DOP_ThumbnailGallery_Container').width($('.DOP_ThumbnailGallery_Container').parents("div").width());
source: http://api.jquery.com/parents/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With