Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Explain this line to me 2

Status
Not open for further replies.

edndori

Programmer
Apr 24, 2003
6
US
var DomYes=document.getElementById?1:0;

It seems to be creating the variable "DomYes" and assigning it a value (which turns out to be 1 ).

But can anyone explain to me what is going on on the right hand side of the "="?

Tips on places where I could learn more about this sort of thing would also be greatly appreciated.

Ed
 
It's called a ternary expression. It's the same as doing this:

var DomYes
if (document.getElementById) {
DomYes = 1
} else {
DomYes = 0
}
 
Thanks. That helps a lot.

But I still don't understand the significance of:
"document.getElementById".

It looks like it might me a method of the document object, but I don't know what it does or where to find documentation on it.

Any suggestions?
 
document.getElementById retrieves an object reference to an element in your document. Consider:

Code:
<div id=&quot;benlucpicard&quot;>I am a fool.</div>
<button onclick=&quot;document.getElementById('benlucpicard').style.backgroundColor='red'&quot;>
Make it red.</button>



jared@eae.net -
 
Oh. But the purpose of the aforementioned line of code is to check to see if document.getElementById exists. If it does exist, then you know that the browser being tested has at least minimal DOM capabilities.

jared@eae.net -
 
One last (I hope) question then:

I can't find &quot;getElementById&quot; in any of the on-line documentation I know about for Javascript.

Where on the internet can I find documentation for it?
 

quite a few hits there to look through

_________________________________________________________
for the best results to your questions: FAQ333-2924
[sub]01001111 01101110 01110000 01101110 01110100[/sub]
onpnt2.gif
[sup] [/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top