Click to See Complete Forum and Search --> : check if object exist?


pelegk1
06-03-2003, 03:42 AM
i want to check if an object for example like div
is exist in my page!
i have in some pages a div like this :
<div id="divName">
</div>

and on some pages i dont load this div

the problem is that if i try to access this i am getting an error
how can i prevent it?
thanks in advance
Peleg

JHL
06-03-2003, 03:57 AM
something like this...

if(document.all)
{
if(document.all[a]!=null)
<!--access layer-->
}
else if(document.getElementById)
{
if(document.getElementById('a')!=null)
<!--access layer-->
}

pelegk1
06-03-2003, 04:50 AM
this :
why do u first do this if's
if(document.all)
if(document.getElementById)

JHL
06-03-2003, 07:35 PM
There are different ways to access layers in different browser.

if(document.all) is to check for Internet Explorer

if(document.getElementById) is to check for other browser that support it

pelegk1
06-04-2003, 07:20 AM
i tried to use the code u gave me to check if a certain tr or td exist!!!!!!

i have tried to do :
alert(document.all['tr10']!=null);

and
alert(document.all["'tr"+10]!=null);

where i have a table with tr and td
that on of them is :
<td id="tr10" value="sd">

and nothing works
help sos!!!
thanks
peleg

pelegk1
06-04-2003, 07:25 AM
i have tried to do :
alert(document.all['tr10']!=null);

and
alert(document.all["'tr"+10]!=null);
(and i tried the same with document.getElementbyID
and it didt work)

where i have a table with tr and td
that on of them is :
<td id="tr10" value="sd">

and nothing works
help sos!!!
thanks
peleg

pelegk1
06-04-2003, 07:44 AM
working for me hen i do :
alert(document.all['td10'].innerHTML);
it only works when i try to do:

alert("by name : "+document.getElementsByName("td10");

but when i try to do :
alert("by name : "+document.getElementsByName("td10").innerText);

or

alert("by name : "+document.getElementsByName("td10").innerHtml);

which means to get the text it isnt working :(
what to do?

pelegk1
06-04-2003, 07:58 AM
i have done on a clean page a table
and when i did
document.getElementById('td11').innerText="u have been changed";
it worked find!