Javascript 带有 jquery 的父容器的宽度

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6992082/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 00:10:11  来源:igfitidea点击:

Width of the parent container with jquery

javascriptjquerycss

提问by Silviu Claponea

How can I set "DOP_ThumbnailGallery_Container" to have the width of the parent container

如何将“DOP_ThumbnailGallery_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!

我什至试图隐藏溢出的外部容器,但它打破了它!

回答by neokio

Or something like ...

或者类似...

http://jsfiddle.net/y3597/2/

http://jsfiddle.net/y3597/2/

$('#object').width($('#object').parent().width());

回答by evasilchenko

Have you looked at the parents function of jquery?

你看过jquery的parents函数吗?

You can do something like this:

你可以这样做:

$('.DOP_ThumbnailGallery_Container').width($('.DOP_ThumbnailGallery_Container').parents("div").width());

source: http://api.jquery.com/parents/

来源:http: //api.jquery.com/parents/