1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > jQuery给多个不同元素添加class样式的方法 – CSS – 前端 css3 选择不是最后一个

jQuery给多个不同元素添加class样式的方法 – CSS – 前端 css3 选择不是最后一个

时间:2018-07-03 07:39:03

相关推荐

jQuery给多个不同元素添加class样式的方法 – CSS – 前端 css3 选择不是最后一个

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”);

$(“div”).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>

<div>This is some important text!</div>

<br>

<button>Add classes to elements</button>

</body>

</html>

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。