Luca wrote:
Hi everyone,
I'm super-newbie here... so thanx in advance for any help
I shoud give a "value" to an DIV's ID that change following the name of the
directory where the file is.
For example the file is here:
www.website.com/web/01/file.html
Is it possible with javascript to give the value "01" to the DIV's ID?
<div id="namedirectory"something inside </div>
so it could be readed as:
<div id="01"something inside </div>
I found in internet this one:
<script language="JavaScript">
fullpath=location.pathname;
document.write(fullpath);
document.write('<br />');
result=fullpath.split("\\");
document.write(result[5]);
</script>
it's something that could work?
I don't know how to recall the value in the ID...
Thanx a lot
Cheers,
Luca
Hi Luca.
If I understand what you want to do correctly, you should be able to do
this.
var div = document.getElementById('01');
div will now become a pointer to the dic element with th id of 01.
I would just like to point out, that as a rule of thumb, ALL ids should
start with a letter, and not a number.
'd1' would be an acceptable id name, whereas '1d' would not be as it
starts with a number. Also, ids need to be unique.
If you wanted to list all the div elements in the document, you can do
this with a while loop like so:
var divs = document.getElementsByTagName('div');
for (var i = 0; i < divs.length; i++)
{
// Do stuff with div her, perhaps alert it's name if it has one,
like so...
alert(divs[i].name);
}
If you want to dynamically change the id of the dive (not that you
should need to), you can do this:
var div = document.getElementById('01');
div.id = 'new_id';
Nice and easy. :)
I hope this helps and I haven't completely missed the question.
All the best.
Daz.