如何使用 jQuery 库修改 CSS 类?
在本文中,我们将讨论如何使用 jQuery 修改 css 类。这是 jQuery 的主要应用之一。我们通常在必须为 HTML 的特定元素添加动态样式时使用它。例如,动态更改特定类内容的颜色。
方法:我们将使用addclass()、css()等jQuery库的一些方法来修改HTML元素的CSS。让我们使用以下示例来了解此应用程序。
示例 1:在下面的示例中,我们正在使用 jQuery 修改类(“.gfg_class”)。
HTML
JQuery Examples
Updating the .gfg_class font
Adding border property to the span selector
Setting background color attribute in class (#gfg_id)
Hello this is GFG...
is
Great
Hey,GFG you are great..
HTML
JQuery Examples
step : 1 adding class in div having 'id=someSection'
step : 2 the class gfg_class_2 will added in the div 2 and div 4
where the effect of class gfg_class_1 is consider secondary.
step : 3 div having primary class gfg_class_1 (div 1 and div 3)
also get gfg_class_3 by below line.
step : 4 div having primary class gfg_class_2 (div 2 and div 4)
also get gfg_class_4 by below line
Hello,this is GFG.....
How can I help you ????
Okay ,so you want to code...
Let's begin....
HTML
JQuery Examples
setting the table head background and border
setting the head partition line in white color
text of column containing '2756' will get blue color
text of next column containing 'Sam' will get blue color
text of all column next to the block containing '6.'
will get yellow color
text of row which containing '8.' will get pink color
text of row which containing '8.' will get bold
child element of column containing '2756' will get bold
GFG rating table
S.No.
Name
GFG rating
1.
Jhon
2152
2.
Sam
1235
3.
Tom
960
4.
Roy
2756(leader)
5.
Bob
1456
6.
Simmy
352
7.
Son
965
8.
Ron
1745
输出:通过使用文本编辑器创建一个 .html 文件来运行上述代码。
示例 2:在本示例中,您将了解“如何在部门中添加类? “,以及它的一些属性,以便正确理解,跟随评论并与下面的输出进行比较。
HTML
JQuery Examples
step : 1 adding class in div having 'id=someSection'
step : 2 the class gfg_class_2 will added in the div 2 and div 4
where the effect of class gfg_class_1 is consider secondary.
step : 3 div having primary class gfg_class_1 (div 1 and div 3)
also get gfg_class_3 by below line.
step : 4 div having primary class gfg_class_2 (div 2 and div 4)
also get gfg_class_4 by below line
Hello,this is GFG.....
How can I help you ????
Okay ,so you want to code...
Let's begin....
输出:通过使用文本编辑器创建一个 .html 文件来运行上述代码。
示例 3:在本示例中,您将了解“如何在表格中添加类?”以及“如何在表格的不同块、行和列中设置不同类型的样式?为了正确理解,请遵循评论并与以下输出进行比较。
HTML
JQuery Examples
setting the table head background and border
setting the head partition line in white color
text of column containing '2756' will get blue color
text of next column containing 'Sam' will get blue color
text of all column next to the block containing '6.'
will get yellow color
text of row which containing '8.' will get pink color
text of row which containing '8.' will get bold
child element of column containing '2756' will get bold
GFG rating table
S.No.
Name
GFG rating
1.
Jhon
2152
2.
Sam
1235
3.
Tom
960
4.
Roy
2756(leader)
5.
Bob
1456
6.
Simmy
352
7.
Son
965
8.
Ron
1745
输出:通过使用文本编辑器创建一个 .html 文件来运行上述代码。