...And Javascript is client-side and so can be a bit of a pain like cross-compatibility in HTML. One of the functions that really sticks out with its bad cross-compatibility is the
add function for select fields, but thankfully Javascript has support for try and catch blocks and so it's really quite simple:
javascript Code:
pSelect = document.getElementById('mySelect');
pOption = document.createElement('option');
pOption.innerHTML = 'This is my option';
try
{
pSelect.add(pOption, null);
}
catch(pEx)
{
pSelect.add(pOption);
}
You have to do that because Internet Explorer doesn't support the second argument, whereas
all other browsers requires you at least to set it to
null.
With the increasing popularity of Javascript frameworks such as Prototype and jQuery, browser incompatibilities, such as
class and
className, as well as CSS opacity in JS, are all relatively easy to overcome by using the functions from the frameworks which try their utmost to increase that compatibility. They do this by simply by wrapping our try and catch block above in a function of their own which we can then call without a try and catch block and have it work perfectly.