It make look like an Array, hell, it even has a length attribute; however, it may not actually be an Array. JavaScript is sometimes a quirky language to say the least and the notion of what is an Array is no exception.

So what are these array-like objects that I speak of? Well there are a few of them, one of which is arguments. arguments is a special variable that is available inside the body of every function. It is in fact, the list of arguments that were passed in.

Read the rest of this entry »

Javascript Kata has a teriffic an article on how to create objects with JavaScript the old fashion way, without any JavaScript libraries. But I use prototype and it has its very own way to create a classes.

Read the rest of this entry »

0

Firebug and the Console API

Posted in JavaScript at February 9th, 2007 / No Comments »

Among the many Firefox extensions out there, there exists Firebug, and it is good. It is truly an amazing piece of software. There is a CSS viewer, so that when you inspect an element in the DOM, you can view all of the CSS attributes that apply to that element. Not only does it show you the applicable CSS rules, it breaks it down to the styles being used and to the styles which have been overwritten. Very nice. There are many other things it does, but one feature in particular that I don’t think I would want to live witout is the console API.

Read the rest of this entry »

Internet Explorer frustrates the living hell out of me. Event though IE 7 is finally out, it doesn’t mean that IE 6 can be ignored. I really look forward to the day when my CSS files aren’t full of unnecessary classes and hacks because the major browser vendors got it right and because everyone has casted away the garbage. Until then, I am still in search of tricks to simplifying my life.

One of these tricks is to make IE pretend like it knows how to use the :hover pseudo-class on all tags.

If you have ever tried to do a suckerfish dropdown, then you have gone through the same thing: excitement as you have learned how to use structural markup to create a dropdown and then frustration as your work has been nullified by IE. The fix involves creating duplicate selectors of those using :hover, but instead of using :hover, replace it with a class name .hover. Making what are essentially duplicates and managing more content doesn’t sit well with me. The other trick to getting suckerfish to work in IE is to use JavaScript. The script will add a class definition to the tag when a user’s mouse if over the element and then removes the class when the users mouse is no longer over it. Since this method uses JavaScript to solve one problem, why not make it solve both?

Read the rest of this entry »

3

Engrish Javascript

Posted in JavaScript at October 20th, 2006 / 3 Comments »

In what I can think of as the most important JavaScript that I have ever written, I have made something which will parse the DOM and replace all of the ‘l’s with ‘r’s. This idea came about after watching Team America: World Police about 1,000 times and after Kim Jong Il gave his apology for doing some nuke testing. Back to the script:

function engrish(n) {
	if(n.nodeType == document.TEXT_NODE) {
		n.nodeValue = n.nodeValue.replace(/l/g, 'r').replace(/L/g, 'R');
	} else if(n.hasChildNodes()) {
		for(var i=0; i<n.childNodes.length; i++) {
			engrish(n.childNodes[i]);
		}
	}
}

To execute this code, simply call engrish(document.documentElement);. Using recursion, this function goes through the DOM, finds text nodes and replaces the characters.

Read the rest of this entry »