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,958
    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,184
    Thanks
    10
    Thanked 569 Times in 550 Posts
    you can use the new nextElementSibling as well.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/1/19) IE7:0.2, IE8:6.7, IE11:7.4, IE9:3.8, IE10:4.4, FF:18.3, CH:43.6, SF:7.8, MOBILE:27.5

  • #3
    Regular Coder
    Join Date
    Aug 2010
    Posts
    945
    Thanks
    19
    Thanked 205 Times in 203 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
    •