HighDots Forums  

getElementById behavior in Sarari

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss getElementById behavior in Sarari in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Rick Spencer
 
Posts: n/a

Default getElementById behavior in Sarari - 01-29-2006 , 06:53 PM






Hello:

I want to test if an element exists on a page and display appropriate UI
to the user depending on if the element was there.

function foo()
{
if(document.getElementById('element') == null )
{
//element was not there
//do something appropriate
return;
}
//element was there do something else
}

This works fine in Firefox and IE, but the script just busts and stops
working in Safari. I'm a javascript novice, so any advice on how to handle
this situation would be much appreciate.

FWIW, I tried this using $ in the prototype library, and got the same
result. Thanks.

Cheers, Rick

Reply With Quote
  #2  
Old   
Mike Scirocco
 
Posts: n/a

Default Re: getElementById behavior in Sarari - 01-31-2006 , 01:06 AM






<snip>
Quote:
1. It's Safari 3.2.1

2. My program is rendering HTML and javascript on the server. Sometimes it
renders 'element' and sometimes it doesn't. document.getElementById works
properly in Safari when 'element' is there, so I know the browser supports
the function. When 'element' is not there it's as if Safari never returns
from the function instead of returns null.

1) Is the id always unique when it occurs?

2) Did you try renaming "element" to something less 'dangerous'
sounding? These pages recommends against using "element":

http://www.javascripter.net/faq/reserved.htm
http://www.felgall.com/jsref1.htm
http://www.quackit.com/javascript/ja...rved_words.cfm

3) What does this code do?

function findid(id){
var unique_element = document.getElementById(id);
if (unique_element == null){
alert('Unknown section id: "' + id + '"');
}else{
alert('An element with the id: "' + id + '" was Found!'
}
}

Mike



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.