搜索文档
首页
HTML/CSS
JavaScript
服务端开发
Java教程
移动端
数据库
当前位置:
首页
JavaScript
jQuery 教程
jQuery 操作方法
源代码
清空
点击运行
<!DOCTYPE html> <html> <title>jQuery - addClass添加类名示例 - 基础教程(div.cn)</title> <head> <style> .highlight { background-color: yellow; color: red; } </style> <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("p:first").addClass("highlight"); }); }); </script> </head> <body> <p>这是第一段。</p> <p>这是第二段。</p> <p>这是第三段。</p> <p>这是最后一段。</p> <button>在第一个p元素中添加一个类名</button> </body> </html>
运行结果