...

View Full Version : function to prototype



BubikolRamios
06-22-2012, 05:27 AM
This works, purpose = avoid spaces


function nextObject(obj)
{
var nextS=obj.nextSibling;
while(nextS.nodeType!=1)
{
nextS=nextS.nextSibling;
}
return nextS;
}


In prototype form:



Element.prototype.nextObject = function()
{
var nextS=this.nextSibling;
while(nextS.nodeType!=1)
{
nextS=nextS.nextSibling;
}
return nextS;
}




...parentNode.nextObject...


I get 'is not a function'

?

rnd me
06-22-2012, 06:31 AM
you can use the new nextElementSibling as well.

DaveyErwin
06-22-2012, 01:20 PM
This works, purpose = avoid spaces


function nextObject(obj)
{
var nextS=obj.nextSibling;
while(nextS.nodeType!=1)
{
nextS=nextS.nextSibling;
}
return nextS;
}


In prototype form:



Element.prototype.nextObject = function()
{
var nextS=this.nextSibling;
while(nextS.nodeType!=1)
{
nextS=nextS.nextSibling;
}
return nextS;
}




...parentNode.nextObject...


I get 'is not a function'

?


<!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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum