jQuery USES the addClass of method to add multiple class styles to an element

  • 2020-05-19 04:05:39
  • OfStack

This example shows how jQuery USES the addClass() method to add multiple class styles to an element. Share with you for your reference. The details are as follows:

jQuery adds multiple class elements through the addClass() method. You can just separate multiple class elements with Spaces in the added class


<!DOCTYPE html>
<html>
<head>
<script src="js/jquery.min.js">
</script>
<script>
$(document).ready(function(){
 $("button").click(function(){
  $("#div1").addClass("important blue");
 });
});
</script>
<style type="text/css">
.important
{
font-weight:bold;
font-size:xx-large;
}
.blue
{
color:blue;
}
</style>
</head>
<body>
<div id="div1">This is some text.</div>
<div id="div2">This is some text.</div>
<br>
<button>Add classes to first div element</button>
</body>
</html>

I hope this article has been helpful to your jQuery programming.


Related articles: