Differences between revisions 2 and 3
Revision 2 as of 2009-07-13 16:01:45
Size: 757
Editor: CarlNobile
Comment:
Revision 3 as of 2009-07-13 16:02:08
Size: 742
Editor: CarlNobile
Comment:
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
When you cannot use a [[JavaScript|!JavaScript]] toolkit like [[http://jquery.com|jQuery]] these functions may come in handy. When you cannot use a !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;
}

JavaScriptHelperFunctions (last edited 2009-07-17 20:58:15 by CarlNobile)