Differences between revisions 4 and 5
Revision 4 as of 2009-07-13 16:03:27
Size: 790
Editor: CarlNobile
Comment:
Revision 5 as of 2009-07-16 17:30:43
Size: 823
Editor: CarlNobile
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 toolkit like [[http://jquery.com|jQuery]] these functions may come in handy. However, they do not work in IE.

JavaScript Helper Functions

When you cannot use a JavaScript toolkit like jQuery these functions may come in handy. However, they do not work in IE.

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;
}

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