Use JavaScript scripts to program elements with high levels of elements and container elements

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.