View Single Post
Old 12-23-2011, 11:46 PM   PM User | #4
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 454 Times in 452 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
no.

first you have to figure out how many elements you're working with. If you're working with every div on your page, it's simple using document.getElementsByTagName("div")

then you loop through them. here's a simple example:

Code:
<body>
<input type="button" value ="change divs" onclick="changeDivs()"/>
<div id="myid0" style="background-color:red; width:100px">one</div>
<div id="myid1" style="background-color:red; width:100px">two</div>
<div id="myid2" style="background-color:red; width:100px">three</div>
<script type="text/javascript">
function changeDivs() {
var divs=document.getElementsByTagName("div")
for(var j = 0; j<divs.length; j++){
document.getElementById('myid'+j).style.width= 200+"px";
    }
}	
</script>
</body>
but I assume from your += that what you want to do is to make them 200 pixels wider than what they already are, and what they already are need not be defined. is that the case?
xelawho is offline   Reply With Quote