Consider the JavaScript below:
var v;
if (this.children.length > 0) {
v = this.firstElementChild.value;
}
This works in modern versions
If your code is in an event handler and the function is bound with "attachEvent" the "this" keyword is bound to the "window" object and not the HTMLElement. Try:
function doSomething(e) {
var targ;
if (!e) var e = window.event;
if (e.target) targ = e.target;
else if (e.srcElement) targ = e.srcElement;
if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode;
}
Check http://www.quirksmode.org/js/events_properties.html.