spudly.shuoink.com

the best way to predict the future is to implement it

Entries Comments


Object.hasClass()

1 December, 2007 (21:31) | JavaScript | No comments

Update: For compatibility, Object.hasClass(className) is being changed to simply hasClass(node, className).
Inspired by the dojo toolkit, this function checks to see if a given class is assigned to a node. Simply run it like this:
var my_node = document.getElementsById(”mydiv”);
if( hasClass(my_node, “myclass”) ) {
// …do something
}
Enough talk; here’s the code:
function hasClass( /*HTMLElement:*/node, /*String:*/value ) {
return [...]

the ultimate getElementsBy*: Object.getElementsWhere()

1 December, 2007 (21:14) | JavaScript | 3 comments

Update: for compatibility, Object.getElementsWhere(”condition”) is being changed to getElementsWhere(node, condition) where node is the node to search in.
I’ve looked a lot lately at the getElementsByClass() function and other getElementsBy functions, but they all seemed rather inadequate to me.
I rewrote the function about three times before I figured out what to do. What I really wanted [...]