My code works in IE but breaks in Safari, Firefox, and Opera. (big surprise)
document.getElementById("DropList").options.length=0;
After searching, I've learned that it's the length=0
that it doesn't like.
I've tried ...options=null
and var clear=0; ...length=clear
with the same result.
I am doing this to multiple objects at a time, so I am looking for some lightweight JS code.
Using JQuery is a prettier, shorter & smarter way to do it!
Go reverse. Reason is size decreases after each remove.
I'd like to point out that the problem in the original question is not relevant today anymore. And there is even shorter version of that solution:
I've tested that both versions work in Firefox 52, Chrome 49, Opera 36, Safari 5.1, IE 11, Edge 18, latest versions of Chrome, Firefox, Samsung Internet and UC Browser on Android, Safari on iPhone 6S, Android 4.2.2 stock browser. I think it is safe to conclude that it's absolutely compatible with whatever device there is right now, so I recommend this approach.