我是靠谱客的博主 悦耳外套,这篇文章主要介绍jquery中怎样增加class,现在分享给大家,希望可以做个参考。

本教程操作环境:windows10系统、jquery3.2.1版本、Dell G3电脑。

jquery中怎样增加class

jquery提供了一个addClass()添加class类的方法,可以通过这个方法对标签进行class类添加。通过点击按钮添lass类使字体变大进行addClass()方法的演示。

addClass() 方法向被选元素添加一个或多个类。

该方法不会移除已存在的 class 属性,仅仅添加一个或多个 class 属性。

示例如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<html> <head> <script type="text/javascript" src="/jquery/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("p:first").addClass("intro"); }); }); </script> <style type="text/css"> .intro{ font-size: 40px; } </style> </head> <body> <h1>This is a heading</h1> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <button>向第一个 p 元素添加一个类</button> </body> </html>
登录后复制

输出结果:

+3.gif

相关视频教程推荐:jQuery视频教程

以上就是jquery中怎样增加class的详细内容,更多请关注靠谱客其它相关文章!

最后

以上就是悦耳外套最近收集整理的关于jquery中怎样增加class的全部内容,更多相关jquery中怎样增加class内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(93)

评论列表共有 0 条评论

立即
投稿
返回
顶部