Addon JavaScript Code Snippets

These JavaScript scripts can be used in conjunction with other snippets to enhance their usefulness. These can save you a great deal of time. Many of these are generic and can be used in most snippets.

Results via Envato Market

Use this snippet to insert a node after another node. Quite handy in laying out Web pages.

Obtain the contents of an XML element and convert it to text. This script is great for using with Ajax-type applications, when it’s neccessary to send back the contents of an element to the server without knowing what’s there.

A JavaScript-based library for managing browser history (back button) and providing support for deep linking for Flash and Ajax applications.

This code returns the position of a given element in a given container, relative to other elements of its type. Very useful for finding position indexes of list items, pictures, form items, and more.

When a layer is inside another layer, it’s style.left and style.top positions can both be ‘0’ but the layer itself can be 500 pixels away from the actual margin. These functions will return the true offset.

Use this snippet to get the rendered style of an element. Quick and simple to implement.

A quick and elegant way of grabbing elements by a class name. JavaScript provides functions for obtaining elements by id, name, and tag name, but not by class. This function will do the trick!

JavaScript does not provide a function for obtaining elements by class, only by id, name, and tag name. This snippet will accomplish that, and includes optional arguments with defaults and support for multiple classnames in any order. It works in IE, Firefox, Opera, Safari and IE Mac.

This JavaScript function will obtain elements by class name. If you want to apply a certain event to some elements, you can loop through the elements in the page and then apply the event accordingly, assigning them to those elements that have a certain class name.

The document.getElementById method is very useful but isn’t supported in early browsers. To define the method for use in those older browsers, just add this snippet to the beginning of your scripts.

Ever run into a situation where you want to get an array of all elements with a specific attribute? Or even want elements with a certain value for that chosen attribute as well? Just add this code snippet to your script and your problem will be solved.

A function that returns an array of elements based on DOM element, tag, and class name. For instance, getElementsByClassName(document, ‘tr’, ‘info’) will return an array of all “tr” tags under the document node having the “info” class.

Use this script to target which files you will include on a designated Web page. Easy to set-up and use.

Use this snippet to display text on a Web page when testing and doing design layout work. The amount and type of text can easily be changed, according to your preferences and needs.