Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Width of the parent container with jquery

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!

like image 337
Silviu Claponea Avatar asked Aug 09 '11 06:08

Silviu Claponea


People also ask

How do you find the width of a parent element?

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.

How do I set the width of an element in jQuery?

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.

How do you take full width of a parent DIV?

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).

What does parent () do in jQuery?

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.


1 Answers

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/

like image 74
evasilchenko Avatar answered Sep 25 '22 16:09

evasilchenko