Source Code: (back to article)
<!DOCTYPE html>
<html>
<head>
<style>
.style {
width: 150px;
height: 50px;
background-color: #1c87c9;
text-align: center;
font-size: 20px;
color: #e6ebef;
margin-bottom: 10px;
padding: 5px;
}
</style>
</head>
<body>
<p>Cliquez sur le bouton pour définir une catégorie pour div.</p>
<div id="Div">
Je suis un élément DIV
</div>
<button onclick="myFunction()">Click</button>
<script>
function myFunction() {
document.getElementById("Div").className = "style";
}
</script>
</body>
</html>