Js get the div height and reset the div height and width

Source: Internet
Author: User

Js get the div height and reset the div height and width

Js get the div height and reset the div height and width

<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.111cn.net/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> js obtains the div height and resets the div height and width. </title>
<Script language = "javascript tutorial">
Var $ = function (id ){
Return document. getElementById (id );
}
 
Function clickDiv ()
{
$ ('Testid'). offsetWidth; // 20
$ ('Testid'). offsetHeight; // 200
 
Document. all. testid. style. width = "1000px"; // js sets the div width
Document. all. testid. style. height = "500px"; // sets the div height to democracy.
// Set the height and width of testid again.
// $ ('Testid'). offsetWidth = 300;
// $ ('Testid'). offsetHeight = 300;
 
$ ('Testid'). style. className = 'idtest ';
}
 
</Script>
Method 2
<Script type = "text/javascript">
Alert (document. getElementById ("testid"). scrollHeight + 'px ');
</Script>

Method 3

<Script type = "text/javascript">
Alert (document. getElementById ("testid"). clientHeight + 'px ');
</Script>
<Style type = "text/css tutorial">
# Testid {
Height: 50px;
Width: 200px;
Background: # 3300CC;
}
. Idtest {
Height: 80px;
Width: 150px;
Background: # FFFFFF;
}
</Style>
</Head>

<Body>
<Div id = "testid">
</Div>
<Input type = "button" value = "click" onclick = "clickDiv ();"/>
</Body>
</Html>

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.