How to change width and height of div using javascript?

Sandhyab
Posted by Sandhyab under JavaScript category on | Points: 40 | Views : 1385
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" id="btnClick" value="Click" onclick="fun()" />
</div>
<div id="divExample" style="background-color: Green; width:500px;">
This is div text</div>
<script type="text/javascript" language="javascript">
function fun() {

var div1 = document.getElementById("divExample");
if (div1.style.width != "100px") {
w = div1.style.width;
h = div1.style.height;
div1.style.width = "100px";
div1.style.height = "100px";
}
else
{
div1.style.width = w;
div1.style.height = h;
}
return false;

}
</script>
</form>
</body>
</html>

Comments or Responses

Login to post response