DOMAssistantCSS Module

The DOMAssistantCSS module offers various methods for adding and removing CSS classes, checking if an element has a certain class and getting the rendered style for a specific property on an element.

addClass(className)

Adds a class name to the current element, unless it already exists.

Parameters

className
Desired class name to be added. Required.

Return value

Element which called the method.

Example calls

$("container").addClass("selected");

removeClass(className)

Removes a class name from the current element.

Parameters

className
Desired class name to remove. Required.

Return value

Element which called the method.

Example calls

$("container").removeClass("selected");

hasClass(className)

Checks whether the current element has a certain class name.

Parameters

className
Class name to check if it exists on the current element. Required.

Return value

Boolean. Whether the element has the requested class or not.

Example calls

$("container").hasClass("selected");

setStyle(style, value)

Sets one or several styles inline of an element. Note: it uses CSS syntax instead of JavaScript property syntax. I.e. background-color instead of backgroundColor etc.

Parameters

style
CSS property to set. Can be a string, and is then used in conjunction with the value, or as an object with several style values. Required.
value
The value of the desired style, if the style parameter is a string. Optional.

Return value

Element which called the method.

Example calls

$("#container").setStyle("border", "10px solid red");

$("#container").setStyle({
	background : "#ffffa2",
	color : "#f00",
	opacity : 0.5
});

getStyle(cssRule)

Gets the rendered style for a certain CSS property on the current element, no matter if it was applied inline or from an external stylesheet. Note: make sure to look for the specific property instead of general ones. I.e. background-color instead of background etc.

Parameters

cssRule
CSS property to check value of. Use CSS syntax for the property, i.e. background-color instead of backgroundColor. Required.

Return value

String. The value of the requested style.

Example calls

$("container").getStyle("background-color");

Get your copy