如何利用 jQuery 選中多個元素?
利用 jQuery,可以輕鬆地選中多個元素。以下是如何選中諸如 <h1> 和 <p> 等多個元素:
$("h1, p")
可以嘗試執行以下程式碼以瞭解如何透過 jQuery 選中多個元素 −
示例
<html> <head> <title>jQuery Example</title> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function() { $("h1, p").css("color", "green"); }); </script> </head> <body> <div> <h1>Heading</h1> <p>This is demo text.</p> </div> </body> </html>
廣告