If it has a known id then it's simple in modern browsers:
Code:
function testForObject(Id, Tag)
{
var o = document.getElementById(Id);
if (o)
{
if (Tag)
{
if (o.tagName.toLowerCase() == Tag.toLowerCase())
{
return o;
}
}
else
{
return o;
}
}
return null;
}
Then you can test for any element with an id of "divMain" with:
Code:
var o = testForObject("divMain");
if (o)
{
//do something will object
}
else
{
alert("No object found.");
}
or you can limit it to objects of a specific type:
Code:
var o = testForObject("divMain", "div");
if (o)
{
//do something will object
}
else
{
alert("No object found with specific tag anme.");
}
--
Joe (
Microsoft MVP - XML)