Style manipulation
var newDiv = $("<div>").html("div content")
.addClass("w-50")
.css({'border': '1px solid red', 'color':'blue'});
$("p").removeClass("myClass noClass")
.addClass("yourClass");
methods | description |
---|---|
css( |
Returns the css property value for the first element. |
css( |
Returns array the CSS property values for the first element. The propNames parameter is an array of one or more CSS properties. |
css( |
Sets the value of a CSS property for each element. The val parameter is a string or number. The func parameter is a function that returns a property value for the current element and has two arguments:
|
css( |
Sets the CSS properties for each element. The objPropVals parameter is an object of property-value pairs like {'border': '1px solid red', 'color':'blue'}. |
addClass(clsNames | func) | Adds classes to each element. The clsNames can be string with space-separated classes or array of class names. The func parameter is a function that returns a string with space-separated classes or array of classes and has two arguments:
|
removeClass( |
Removes classes from each element. The clsNames can be string with space-separated classes or array of class names. The func parameter is a function that returns a string with space-separated classes or array of classes and has two arguments:
|
toggleClass( |
Adds or removes classes from each element. The clsNames can be string with space-separated classes or array of class names. The state parameter is a boolean (not just truthy/falsy) value that determines whether the class should be added or removed. |
toggleClass(func [,state]) | Adds or removes classes from each element. The state parameter is a boolean (not just truthy/falsy) value that determines whether the class should be added or removed. The func parameter is a function that returns a string with space-separated classes or array of classes and has three arguments:
|