Hey people – hehe – I’m going to turn into a daily feature here soon ?
Anyway, I’ve got a .js file with some code that works as below:
[code]
function insertStuff(){
var someVar = “some stuff to say”;
document.getElementById(‘stuff’).innerHtml = someVar;
}
and then in the html page i’ve got
[code]
<html>
<head>
<title>Blah bLah blAh blaH</title>
<script type=”text/javascript” src=”file.js”></script>
</head>
<body onLoad=”insertStuff()”>
<div id=”stuff”></div>
<div id=”stuff1″></div>
</body>
Now, If i only want one insertion of the ‘stuff’ then that’s ok…but what if i want to stick that in the page multiple times… using the same id doesn’t work (cos i guess it’s supposed to be unique) and only the first one will show.
My thoughts were to use a for loop or something like that and use a standard … like id=”stuff1″ then next one would be id=”stuff2″. And the in the for loop just iterate a variable i and have document.getElementById(‘stuff+i).
If i do that – how would i count the number of instances of an id that starts with ‘stuff’ – or is there a more efficient way of doing all this?
Cheers for any help