-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjQclasses.txt
31 lines (25 loc) · 1.05 KB
/
jQclasses.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
jQuery Manipulating CSS
jQuery has several methods for CSS manipulation. We will look at the following methods:
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
css() - Sets or returns the style attribute
The following example shows how to add class attributes to different elements. Of course you can select multiple elements, when adding classes:
``
Example
$("button").click(function(){
$("h1, h2, p").addClass("blue");
$("div").addClass("important");
});
```
jQuery removeClass() Method
The following example shows how to remove a specific class attribute from different elements:
Example
$("button").click(function(){
$("h1, h2, p").removeClass("blue");
});
The following example will show how to use the jQuery toggleClass() method. This method toggles between adding/removing classes from the selected elements:
Example
$("button").click(function(){
$("h1, h2, p").toggleClass("blue");
});