Problem:
The parent element (COL) has two sibling elements named col1 and col2 respectively.
The content in col1 or col2 is generated by the server code, and the height does not need to be set by CSS. How can we make the height of the element with the largest sibling element?
The javascript code is as follows: 1 function resizeheight (){
2 If (! Document. getelementsbytagname) return false;
3 var DIV = Document. getelementsbytagname ("Div ");
4 If (! Div) return false;
5 For (VAR I = 0; I <Div. length; I ++ ){
6
7 if (div [I]. parentnode. classname. indexof ("col ")! =-1 ){
8 Col = div [I]. parentnode;
9}
10 if (div [I]. classname. indexof ("col1 ")! =-1 ){
11 col1 = div [I];
12
13 if (Col. offsetheight> col1.offsetheight ){
14 col1.style. Height = col. offsetheight + "PX ";
15}
16 else {
17 col. style. Height = col1.offsetheight + "PX ";
18}
19}
20 else if (div [I]. classname. indexof ("col2 ")! =-1 ){
21 col1 = div [I];
22
23 if (Col. offsetheight> col1.offsetheight ){
24 col1.style. Height = col. offsetheight + "PX ";
25}
26 else {
27 col. style. Height = col1.offsetheight + "PX ";
28}
29}
30}
31
32}
The class definition declaration in the Web document is more common than the ID definition declaration.