...

View Full Version : returns from pop and shift



subhailc
05-24-2005, 08:41 PM
why don't these work?

function init() {var y = document.getElementsByTagName('input'); while(y.length) y.pop().onfocus=function() {this.select();};}
function last() {var y = document.getElementsByTagName('input'); return y.pop();}
swapping shift for pop is no good either. but y[0] will work, strangely enough.

jkd
05-24-2005, 09:51 PM
Because getElementsByTagName is a NodeList, not an Array.

In Mozilla, you can do something like:

NodeList.prototype.pop = Array.prototype.pop;
NodeList.prototype.shift = Array.prototype.shift;

And it works, interestingly enough. But you can't do that in any other browser.

subhailc
05-24-2005, 11:39 PM
thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum