如何結合類選擇器和屬性選擇器以及 jQuery?
jQuery 選擇器是一個函式,它利用表示式以根據指定標準從基於 DOM 中找到匹配的元素。我們可以輕鬆地結合類選擇器和屬性選擇器以及 jQuery。
你可以嘗試執行以下程式碼來了解如何結合類選擇器和屬性選擇器以及 jQuery −
示例
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('.myclass[reference="12345"]').css("background-color", "yellow");
});
</script>
</head>
<body>
<table>
<tr class="myclass" reference="12345">
<td>Row 1 Column 1</td>
</tr>
<tr class="myclass" reference="43215">
<td>Row 2 Column 1</td>
</tr>
<tr class="myclass" reference="54321">
<td>Row 3 Column 1</td>
</tr>
</table>
</body>
</html>
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP