Click to See Complete Forum and Search --> : how do you loop through all div tags?


henryh
08-06-2004, 01:08 PM
im making a menu with lots of div tags and to determine their left style attributes, i need to loop through them all after they're made. How would i do this?
Thnx for reading, hope you respond.

Pittimann
08-06-2004, 01:14 PM
Hi!

Example:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
function getDivs(){
var divs=document.getElementsByTagName('div')
for (var i=0;i<divs.length;i++){
alert(divs[i].style.left);
}
}
//-->
</script>
</head>
<body onload="getDivs()">
<div style="left:0px;"></div>
<div style="left:50px;"></div>
<div style="left:100px;"></div>
<div style="left:150px;"></div>
<div style="left:200px;"></div>
<div style="left:250px;"></div>
<div style="left:300px;"></div>
</body>
</html>Cheers - Pit

steelersfan88
08-06-2004, 02:19 PM
You could handle them in a loop, or store them in array from there on (in place of the alert Pit has put in for you).