Archive for the ‘javascript’ Category

getElementsByClass

December 13, 2005

from


function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i

How it works

It’s simple. It works just how you think getElementsByClass would work, except better.

  • Supply a class name as a string.
  • (optional) Supply a node. This can be obtained by getElementById, or simply by just throwing in “documentâ€? (it will be document if don’t supply a node)). It’s mainly useful if you know your parent and you don’t want to loop through the entire D.O.M.
  • (optional) Limit your results by adding a tagName. Very useful when you’re toggling checkboxes and etcetera. You could just supply “input“. Or, if you’re like me, and you said Good Bye to IE5, you can use the “*â€? asterisk as a catch-all (meaning ‘any element).
  • javascript log

    November 17, 2005

    有个家伙Stephan Strittmatter 写了一个类似log4j的log4js,为javascript的logger。ajaxian也�了介�,许是由于�些原因,先放在了log4j 的bugzilla上�。

    什么是Event Cache

    November 16, 2005

    第一次看到这个�,�是很了解。猜测应该是为了防止�览器(尤其是IE)由于类似循环调用的事件�生,导致内存爆满的现象,而采�的措施。 �考DHTML Leaks Like a Sieve