Reputation: 55
How do I change width
value assigned in #center
? (I don't want to switch between CSS files just because 1 changed width
value.) How do I dynamically change the value using Javascript?
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<style type="text/css">
#main #center {
width: 600px; // change width to 700 on click
float: left;
}
#main #center .send {
background: #fff;
padding: 10px;
position: relative;
}
#main #center .send .music {
text-align: center;
margin-bottom: 10px;
}
#main #center .send .write {
font-family: georgia, serif;
font-size: 150px;
opacity: 0.2;
}
//....etc.
</style>
</head>
<body>
// change #center width to 700
<a href="#go2" onclick="how to change width of #center ???" ></a>
</body>
</html>
Upvotes: 4
Views: 5865
Reputation: 50493
<div onclick="changeWidth()" id="main">
Stuff
</div>
<div onclick="changeWidth()" id="center">
More Stuff
</div>
function changeWidth(){
this.style.width = "700px";
}
Upvotes: 0
Reputation: 6046
Call a javascript function in the onclick which takes the dom element and sets the new width OR changes the class of the element
function changeWidth(){
document.getElementById('center');
div.style.width="1270px";
}
Upvotes: 0
Reputation: 413717
Two possible ways:
Upvotes: 2