...

View Full Version : get element's id knowing element's classname?



maltrecho
09-22-2005, 09:31 AM
Having:

<div class="myDiv" id="div3245">
<div class="myDiv" id="div6534">
<div class="myDiv" id="div1856">

How can I get every div's id?



for (var i = 0; i < document.getElementsByTagName("DIV").length; i++)
{
var thisDiv = document.getElementsByTagName("DIV")[i];

if (thisDiv.className == 'myDiv')
{
thisDivID = ??????????
}
}

glenngv
09-22-2005, 09:45 AM
var divs = document.getElementsByTagName("DIV");
var len = divs.length;
var thisDiv, thisDivID;
for (var i = 0; i < len; i++)
{
thisDiv = divs[i];
if (thisDiv.className == 'myDiv')
{
thisDivID = thisDiv.id;
}
}

maltrecho
09-22-2005, 09:54 AM
:eek:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum