742
Comment:
|
790
|
Deletions are marked like this. | Additions are marked like this. |
Line 6: | Line 6: |
var result = null; |
|
Line 7: | Line 9: |
return this.insertBefore(newNode, refNode.nextSibling); | result = this.insertBefore(newNode, refNode.nextSibling); |
Line 9: | Line 11: |
return this.appendChild(newNode); | result = this.appendChild(newNode); |
Line 11: | Line 13: |
return result; |
JavaScript Helper Functions
When you cannot use a JavaScript toolkit like jQuery these functions may come in handy.
Node.prototype.insertAfter = function(newNode, refNode) { var result = null; if(refNode.nextSibling) { result = this.insertBefore(newNode, refNode.nextSibling); } else { result = this.appendChild(newNode); } return result; } Node.prototype.getElementByClass = function(className, count) { var result = null; for(var i = 0; i < this.childNodes.length; i++) { var classCount = 0; if(this.childNodes[i].className == className) { if(classCount == count) { result = this.childNodes[i]; break; } classCount++ } } return result; }