Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse children recursively using jQuery

Tags:

jquery

I am having my jQuery code as following (which is working fine):

$('[RptrRowEnableAutoHeight=""True""]').each(function () {
        var ch = 10;
        $(this).children().each(function(){ch += $(this).height();}); 
        $(this).height(ch);
});

The above works only for the immediate children of the root element. How can I achieve the same for all nested child elements.

This is a special case for us as the layout was developed using absolute positioning (almost everywhere). At this moment, we are unable to modify entire layout with flow-layout.

In simple, I would like to have all (container) controls to expand (their height/width) automatically to enclose their child elements in a proper fashion (without any scrollbars/hiding).

thanks

like image 324
user203687 Avatar asked Jan 18 '11 20:01

user203687


1 Answers

You can use $(this).find('*').each(...

like image 93
glomad Avatar answered Nov 04 '22 21:11

glomad