Monday, June 29, 2009

Javascript - Elements by Class

// JavaScript Document
// If Core doesn't exist, make it an empty object
Core = Core || {};
Core.getElementsByClass = function(theclass) {

var matchedArray = [];

if (typeof document.all != "undefined") { //Explorer 5.x and other browsers only
elementArray = document.all; //support document.all to retrieve all document
} //elements
else {
elementArray = document.getElementsByTagName("*");
}

//the following variable uses RegExp to find a particular string pattern.
//in this case, it is the name of the class we are searching for.
var pattern = new RegExp("(^| )" + theclass+ "( |$)");

var matchedArray[]; //to hold matched class name elements

//now we need to search through all the collected elements in the document and
//see if they match the class pattern described in the var pattern
for (var i=0; i if (pattern.test(elementArray[i].className)) {
matchedArray[matchedArray.length]=elementArray[i];
}
} //end for loop

return matchedArray;

} //end Core.getElementsByClass


alert("Hello there");

Back and working with PHP/MySQL and some Javascript

Using one of those free hosting sites that allow PHP/MySQL - http://www.atbhost.com in particular - I've started working on php scripts. I've also found Javascript to be helpful.