JavaScript + PHP + MySQL – determine if user is online or logged in

This is a pretty common task that doesn’t have a perfect answer. It’s not possible to determine if a user disconnects, leaves the page, closes the browser, etc (besides window unload methods, which aren’t practical for this use case). So we fake it as best we can. Here’s how I do it. 1. Create a […]

jQuery – zencoding plugin

There are a couple plugins out there that are either incomplete, or don’t adhere fully to the original zencoding spec. Instead of trying to reinvent the wheel, I grabbed the original parser libraries from the author’s repo, modified a little and culled a lot, for a pretty simple, straightforward jQuery plugin. Very easy to use […]

jQuery – test if element is in viewport (visible on screen)

/UPDATE: the most recent version of this plugin is now available on github: Forks (and hopefully improvements) welcome. /UPDATE: if you’re looking for a how-to on lazy-loading content, images, or event effects, there’s a simple outline using this plugin available here. /UPDATE: this is probably all you need. Original Version returns true if any […]

jQuery – element or parent matches selector

This extension tests whether an element matches the passed selector, or if it’s the child of a parent that does. This can be handy for testing user events, such as relatedTarget when mousing-out or dropTarget when using drag-n-drop.


jQuery – test if element is in DOM

jQuery – walk DOM (up or down)

simple function to go “back” up the DOM (parents), or “down” (children). Pass a negative value of parents, a positive value for children… Passing 0 returns self. Will “max out” when reaching an element with no parents (if walking up) or no children (if walking down), and return the last element that did not fail […]

jQuery – get or test tag name

Here’s a simple function I use pretty commonly – has 2 uses. If passed with no arguments, it returns the tag name of the element. If passed with any arguments, it returns true if the element’s tag name matches any of the arguments, false if not.


jQuery – seriously simple tab navigation

There are plugins for this sort of thing, and sometimes people try to find a jQuery UI implementation, but it’s really very simple. Assume you have a UL with class “activators”, and each child LI should show a DIV in the same position in a container with class “tabs”…

While the above is probably […]

jQuery – create element

If you create a lot of dom elements dynamically, the standard jQuery method of wrapping an open tag in an instance can be cumbersome. Here’s some sugar I use pretty frequently:

The above will accept a tag name, with an optional subset of selectors for class and ID, and return a DOM element wrapped […]

jQuery – remove (all) attributes

a little jQuery extension that removes multiple attributes, with white- and black-lists. the first argument is a list of attributes to remove. if omitted, it removes all attributes on the element, except those in the second argument. both are arrays of strings.


This can actually be a handy function for sanitizing HTML […]