/    Sign up×
Community /Pin to ProfileBookmark

DOM, Layers, All

Well i try to use all in my codes to get more support, for example:

if ([COLOR=”Green”]document.getElementById[/COLOR]){
[COLOR=”Red”]String[/COLOR]
}
else{
if ([COLOR=”Green”]document.layers[/COLOR]){
[COLOR=”Red”]String[/COLOR]
}
else{
if ([COLOR=”Green”]document.all[/COLOR])
[COLOR=”Red”]String[/COLOR]
}
else{

[COLOR=”Red”]String[/COLOR]
}
}
}
}

But i was wondering, is there a better way to do this? And also lets say a function is as follows:

function Example(id)

and for document layers for example is it best to do:

document.layers.id.
id.
document.layers[id].

I normally only do one of them for all my scripts however every code seams to do it differently. Does it not matter? Also can someone point me to somewhere i can find out more about this, google is too vague.

what is the correct way to string: document.all and document.layers, im fine with DOM. also is there any more methods i need to take into account?

Thanks a lot.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Jun 26.2007 — With todays browsers all you need is document.getElementById()

document.all and document.layers are for browsers that probbaly 7+ years old now.

Eric
Copy linkTweet thisAlerts:
@TaboauthorJun 26.2007 — I know that much but people allways go on about supporting even the oldest browsers...

and even if it is just 2% of people with a browser that is that old it is still 2 in every 100 visitors.

Anyway front page for vista is the only version to phrase DOM in its code hints, i think older versions did document.all.
Copy linkTweet thisAlerts:
@Banana_AnandaJun 26.2007 — it is still 2 in every 100 visitors[/QUOTE]

But then only 2 in every 100 scripts will work in those 2 in 100 visitors' browsers without further modification, if at all.

To answer you question..

These are synonyms in Javascript. You would only use the square-bracket form if you are carrying the propertyName in a variable.

[code=php]object.propertyName
object["propertyName"][/code]


..for some reason some started to hard-code strings into the 2nd form. It's that cargo cult effect.
Copy linkTweet thisAlerts:
@TaboauthorJun 26.2007 — Ok so document.all wil be:

document.propertyName

adn document layers would be

document.propterName

???
Copy linkTweet thisAlerts:
@Banana_AnandaJun 26.2007 — [code=html]<p id="test">


var elm = document.all.test
var id = "test";
var elm = document.all[id];[/code]
Copy linkTweet thisAlerts:
@felgallJun 27.2007 — document.all is only needed for the two people still using IE4.

document.layers is only needed for the few thousand people still using Netscape 4.

As these together make up less than 0.001% of the typical visitors to a site they are no longer worth catering for unless you are still using JavaScripts written at least three years ago when there were still a significant number of people still using those antiques.
×

Success!

Help @Tabo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...