Home > Web Front-end > JS Tutorial > jQuery uses the addClass() method to add multiple class styles to elements_jquery

jQuery uses the addClass() method to add multiple class styles to elements_jquery

WBOY
Release: 2016-05-16 16:07:26
Original
2365 people have browsed it

The example in this article describes how jQuery uses the addClass() method to add multiple class styles to elements. Share it with everyone for your reference. The details are as follows:

jQuery adds multiple classes to elements through the addClass() method. You only need to separate multiple classes with spaces in the added classes

<!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>
Copy after login

I hope this article will be helpful to everyone’s jQuery programming.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template