im busy with a school project to create a photo viewer type site with java script.
the whole thing i being created from java script and im giving all the img's an ID tag
how do i go about getting the id of the img that i have just clicked.
i know my current code doesn't work properly in IE so help with that would be appreciated as well.
the reason i want the Id is so later i can hopefully use the info to determine which img to "zoom in" etc
function vulpagina()
{
alert("vulpagina geactiveerd, jej");
var maindiv=document.getElementById("maindiv");
for(i=1; i<26; i++)
{
var imgnr = i-1
var div=document.createElement("div");
var img=document.createElement("img");
var br=document.createElement("br");
var txt=document.createTextNode("dit is div " + i);
img.src=album[imgnr].url;
img.style.margin ="10px 50p";
img.style.padding ="10px";
img.style.height="80%";
img.setAttribute('onclick','getImgId(this)');
img.onclick = getImgId;
div.setAttribute("id","divje" + i);
div.appendChild(img)
div.setAttribute('style','float:left');
div.style.width="20%";
div.style.height="20%";
div.appendChild(txt);
maindiv.appendChild(div);
//alert("test");
}
}
function getImgId(obj)
{
alert('test')
imgId = event.srcElement.id
alert(imgId)
}
var album =
[
{
url: 'images/0006787.jpg',
landscape: false,
description: 'Shadows to the sea...',
photographer: 'Sander',
date: new Date('12-8-1999')
},
{
url: 'images/0004713.jpg',
landscape: false
},
{
url: 'images/0004720.jpg',
landscape: false
},
{
url: 'images/0004731.jpg',
landscape: true
}
];