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
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,982
    Thanks
    120
    Thanked 76 Times in 76 Posts

    function to prototype

    This works, purpose = avoid spaces
    Code:
    function nextObject(obj)
    {
      var nextS=obj.nextSibling;
      while(nextS.nodeType!=1)
      {
        nextS=nextS.nextSibling;
      }
      return nextS;
    }
    In prototype form:

    Code:
    Element.prototype.nextObject = function() 
    { 
      var nextS=this.nextSibling;
      while(nextS.nodeType!=1)
      {
        nextS=nextS.nextSibling;
      }
      return nextS;
    }
    Code:
    ...parentNode.nextObject...
    I get 'is not a function'

    ?
    Found a flower or bug and don't know what it is ?
    agrozoo.net galery
    if you don't spot search button at once, there is search form:
    agrozoo.net galery search

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,402
    Thanks
    11
    Thanked 595 Times in 575 Posts
    you can use the new nextElementSibling as well.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    974
    Thanks
    19
    Thanked 212 Times in 210 Posts
    Quote Originally Posted by BubikolRamios View Post
    This works, purpose = avoid spaces
    Code:
    function nextObject(obj)
    {
      var nextS=obj.nextSibling;
      while(nextS.nodeType!=1)
      {
        nextS=nextS.nextSibling;
      }
      return nextS;
    }
    In prototype form:

    Code:
    Element.prototype.nextObject = function() 
    { 
      var nextS=this.nextSibling;
      while(nextS.nodeType!=1)
      {
        nextS=nextS.nextSibling;
      }
      return nextS;
    }
    Code:
    ...parentNode.nextObject...
    I get 'is not a function'

    ?
    Code:
    <!doctype html>
    <head>
    <title>nextObject</title>
    
    </head>
    <body><div>
    <form>
    <input name="input1">
    <input name="input2">
    </form>
    <script>
    Element.prototype.nextObject = function(){
    var nextS=this.nextSibling;
      while(nextS.nodeType!=1)
      {
        nextS=nextS.nextSibling;
      }
      return nextS;
    
    }
    alert(document.forms[0].input1.nextObject().name)//alerts input2
    </script>
    </body>
    </html>


  •  

    Posting Permissions

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