如何使用 jQuery 選中具有多個類別的元素?
要選擇具有多個類的元素,請執行以下操作。在此,x、y 和 z 是我們的類。
$('.x.y.z')你可以嘗試執行以下程式碼,來學習如何在 jQuery 中選擇具有多個類的元素。
<html>
<head>
<title>jQuery Selector Example</title>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$(".one.two").css("background-color", "grey");
});
</script>
</head>
<body>
<div class = "one two" id="div">
<p>This is first division of the DOM.</p>
</div>
<div class = "three" id = "div3">
<p>This is third division of the DOM</p>
</div>
</body>
</html>
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP