<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style>
.first{
color: red;
}
.change{
width: 100px;
height: 60px;
line-height: 60px;
background-color: pink;
margin: 0 auto;
text-align: center;
}
</style>
<body>
<div class="first">HelloWorld</div>
<script>
/*
* 使用element.style获得修改元素样式,如果样式较少或者功能简单的情况下使用.
* 可以使用className方法,鼠标一点击,就给div加上类名
* className会覆盖原来的类名
* 如果想要保留原来的类名,可以加个空格
*/
var div=document.querySelector("div");
div.onclick=function(){
div.className="first change";
}
</script>
</body>
</html>