JavaScript

Getting and Setting Styles and Class Names

Description

The JavaScript functions below provide an easy way to get and set the in-line style, can class of HTML elements. The passed in argument of "ELEMENT" can be a pointer to an HTML element, or the ID or NAME of an HTML element. The functions will automatically fetch the element if you pass in an ID or NAME.

Name
Description
$acn()

The $acn() function adds the class name to the passed-in HTML element(s). This will not overwrite any class names the already being using by the element(s). Instead, the new CSS classes will be used in addition to the class names already in use on the element(s). The added class name is the added as the last class name in the list of class names for the element. This means that any style attribute that duplicates a style attribute in one of the existing class names will override the existing style attribute.

$gs()

The $gs() function gets the in-line style of the passed-in element(s), and returns the CSS text.

$rcn()

The $rcn() function removes the class name from the passed-in element(s). This will only remove the specified class name. You might want to use this to remove some temporary styling to an element, such as a focus, or error style. This function is typically used after the $acn() function has been used to add a class name to an element.

$scn()

The $scn() function sets the class name of the passed-in element(s). This will overwrite any class names the already being using by the element(s). Contrast this with the $acn() function which adds the class name to the element.

$ss()

The $ss() function sets the in-line style of the passed-in element(s). It takes a second parameter of a JSON (Javascript Object Notation) object of the style attributes to set.

See Also