Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Posts
    185
    Thanks
    2
    Thanked 1 Time in 1 Post

    returns from pop and shift

    why don't these work?
    Code:
    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.

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Jan 2004
    Posts
    185
    Thanks
    2
    Thanked 1 Time in 1 Post
    thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •