CSS Classes

With SniperJs, it is easy to manipulate the style of elements.


SniperJs Manipulating CSS

SniperJs has several methods for CSS manipulation. We will look at the following methods:

  • hasClass() - Checks if the HTML element has a specified class.

  • addClass() - Adds one or more classes to the selected elements

  • removeClass() - Removes one or more classes from the selected elements

  • toggleClass() - Toggles between adding/removing classes from the selected elements

  • setClass() - This sets a new class for the element

  • css() - Sets or returns the style attribute

Adding class names

$(".button").hasClass('move'); // returns true or false

Adding class names

sniper.js
$(".button").addClass('move');

Removing class names

$(".button").removeClass('move');

Replacing class names

Toggling class name

Setting new class

Setting multiple classes at once


Working with more than one elements

Checking if multiple elements has a class name

Adding a class name to multiple elements

Removing a class name from multiple elements

Replacing a class name for multiple elements

Toggling a class name for multiple elements

Setting class name for multiple elements


SniperJs css() Method

The SniperJs css() method will be explained in the next chapter.

Last updated