How can I write a script to use either W3C DOM or IE 4 DOM depending on their availability?


If you want to write a script with the flexibility to use either W3C DOM or IE 4 DOM depending on their availability, then you can use a capability-testing approach that first checks for the existence of a method or property to determine whether the browser has the capability you desire.

The following is the code snippet showing the same −

if (document.getElementById) {
   // If the W3C method exists, use it
}

else if (document.all) {
   // If the all[] array exists, use it
}

else {
   // Otherwise use the legacy DOM
}

Updated on: 23-Jun-2020

59 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements