⇤ ← Revision 1 as of 2009-07-13 15:58:43
Size: 743
Comment:
|
Size: 757
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 2: | Line 2: |
When you cannot use a JavaScript toolkit like [[http://jquery.com|jQuery]] these functions may come in handy. |
When you cannot use a [[JavaScript|!JavaScript]] toolkit like [[http://jquery.com|jQuery]] these functions may come in handy. |
JavaScript Helper Functions
When you cannot use a !JavaScript toolkit like jQuery these functions may come in handy.
Node.prototype.insertAfter = function(newNode, refNode) { if(refNode.nextSibling) { return this.insertBefore(newNode, refNode.nextSibling); } else { return this.appendChild(newNode); } } 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; }