2.5 KiB
.css
Description Get the value of a computed style property for the first element in the set of matched elements or set one or more CSS properties for every matched element.
Parameters
property(String|Object): A CSS property name or an object of property-value pairs.value(String|Number, optional): A value to set for the property.
Returns
- (String): The value of the property (if getter).
- (jBase): Current instance (if setter).
Example
// Get value
const color = $('.box').css('color');
// Set single value
$('.box').css('width', '500px');
// Set multiple values
$('.box').css({
'background-color': 'blue',
'font-size': '14px'
});
.addClass
Description Adds the specified class(es) to each element in the set of matched elements.
Parameters
className(String): One or more class names to be added to the class attribute of each matched element.
Returns
- (jBase): Current instance.
Example
$('p').addClass('lead text-muted');
.removeClass
Description Remove a single class, multiple classes, or all classes from each element in the set of matched elements.
Parameters
className(String): One or more class names to be removed.
Returns
- (jBase): Current instance.
Example
$('.active').removeClass('active');
.toggleClass
Description Add or remove one or more classes from each element in the set of matched elements, depending on either the class's presence or the value of the state argument.
Parameters
className(String): One or more class names to be toggled.
Returns
- (jBase): Current instance.
Example
$('.btn').click(function() {
$(this).toggleClass('btn-active');
});
.hasClass
Description Determine whether any of the matched elements are assigned the given class.
Parameters
className(String): The class name to search for.
Returns
- (Boolean): True if the class is present, false otherwise.
Example
if ($('#menu').hasClass('open')) {
$('#menu').slideUp();
}