faqts : Computers : Programming : Languages : JavaScript : DHTML

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

2 of 4 people (50%) answered Yes
Recently 2 of 4 people (50%) answered Yes

Entry

How do I assign a var to take the place of document.all & document.layer & document.getelementbyid

Jul 25th, 2003 08:16
Kasey, Pete Ruby,


The best answer I can give you involves conditional expressions to 
assign a value of true(1) or false(0) to variables.
Here's an example,
<script type="text/JavaScript">
<!--
// assigns 1 to myvariable1 if document.layers
// is true and assigns 0 if it's false
var myvariable1 = (document.layers)?1:0;
var myvariable2 = (document.all)?1:0;
var myvariable3 = (document.getelementbyid)?1:0;
// Pop up an alert box with the results of the variable assignments
alert(myvariable1+ "\n" +myvariable2+ "\n" +myvariable3);
// -->
</script>
I hope this helps.