JS Get div Width code

Source: Internet
Author: User
Keywords Web page production Ajax javascript
Tags access ajax button code document get javascript jpg

To provide three of the use of JS to obtain div width code Oh, the first simple and practical, the second access to the div width and height of the JS instance, the third instance is an S to get the specified div inside all the picture height and width code.

<input type= "button" onclick= "Calculate ()" value= "Test" >

<script>
function Calculate () {
var divs = document.getElementById ("Showtemptext");
Divs.innerhtml= "Wuao Ahshahsah <font size=6>jzread.com</font>";
Alert (divs.scrollwidth + "__" + divs.scrollheight);
}
</script>


<html>
<head>
<title>test page</title>
</head>
<body>
<table style= "width:100%;"
   <tr>
    <td>
     <div id= "Div1" Style= "Background:green;" >div1</div>
    <td>
    <td style= "width:50%;"
     <div id= "Div2" style= "background-color:red;" >div2 www.jzread.com</div>
    <td>
</table>
<input type= "button" Onclick= ' Show () ' value= ' show '/>
<script>
function Show ()
{
    var o = document.getElementById ("Div1");
    var w = o.clientwidth| | O.offsetwidth;
   
    alert ("Div1 s width is" wheels);
}
</script>
</body>
</html>
Here is a use of JS to get the specified div inside all the picture height and width js How to get this div inside the width of the picture and

<div style= "width:100000px" id= "pal"
                     <img src= "/www.jzread.com/images/2009021121575533977. JPG "width=" "486" height= "348"/>
                     <img src= "images/2009021121575533977.jpg"/>
                     <img Src= "Images/2009021121575533977.jpg"/>
                     <img src= "images/2009021121575533977.jpg"/>
                     <img src= "images/2009021121575533977.jpg"/>
                     <img src= "images/2009021121575533977.jpg"/>
                     <img src= "images/2009021121575533977.jpg"/>
                     <img src= "images/2009021121575533977.jpg"/ >
                     </div>

<script>
var obj=document.getelementbyid ("Pal");
var imgs=obj.getelementsbytagname ("img");
Var sum=0;
for (var i=0;i<imgs.length;i++)
 sum+=imgs[i].width
Alert (sum);
</script>

Related Article

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.