View Full Version : returns from pop and shift

05-24-2005, 07: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.

05-24-2005, 08: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.

05-24-2005, 10:39 PM

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum