当前位置: 移动技术网 > IT编程>开发语言>JavaScript > jQuery给多个不同元素添加class样式的方法教程

jQuery给多个不同元素添加class样式的方法教程

2019年05月17日  | 移动技术网IT编程  | 我要评论

本文实例讲述了jquery给多个不同元素添加class样式的方法。分享给大家供大家参考。具体分析如下:

jquery可以通过addclass()方法给多个不同的html元素同时添加相同的class

<!doctype html>
<html>
<head>
<script src="js/jquery.min.js">
</script>
<script>
$(document).ready(function(){
 $("button").click(function(){
  $("h1,h2,p").addclass("blue");
  $("p").addclass("important");
 });
});
</script>
<style type="text/css">
.important
{
font-weight:bold;
font-size:xx-large;
}
.blue
{
color:blue;
}
</style>
</head>
<body>
<h1>heading 1</h1>
<h2>heading 2</h2>
<p>this is a paragraph.</p>
<p>this is another paragraph.</p>
<p>this is some important text!</p>
<br>
<button>add classes to elements</button>
</body>
</html>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网