How does Javascript obtain and set the height and width of a div, and is compatible with any browser, if you are interested, you may wish to see the following code and perhaps unexpected gains. How does Javascript get and set the height and width of p and be compatible with any browser? Check the Code:
The Code is as follows:
Http://www.itdos.com
Http://www.itdos.com
Obtain the width and height of p1:
The Code is as follows:
Alert (document. getElementById ("p1"). offsetHeight); // compatible with FF, IE, etc.
Alert (document. getElementById ("p1"). offsetWidth); // compatible with FF, IE, etc.
Set the width and height of p1 to the width and height of p2:
The Code is as follows:
Document. getElementById ("p1"). style. height = document. getElementById ("p2"). offsetHeight; // only IE
Document. getElementById ("p1"). style. height = document. getElementById ("p2"). offsetHeight + "px"; // compatible with FF, IE, etc.
Document. getElementById ("p1"). style. width = document. getElementById ("p2"). offsetWidth; // only IE
Document. getElementById ("p1"). style. width = document. getElementById ("p2"). offsetWidth + "px"; // compatible with FF, IE, etc.