jQuery 元素選擇器
jQuery 中的元素選擇器用於選擇具有特定元素名稱的所有元素。
語法
語法如下 -
$("ele")
在上面,ele 是要選擇的元素。
示例
現在讓我們看一個實現 jQuery 元素選擇器的示例 -
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("h2").css("color", "orange"); }); }); </script> </head> <body> <h2>Student Info</h2> <p>This is a demo text.</p> <h2>Exam Info</h2> <p>This is a demo text.</p> <h2>Teacher's Info</h2> <p>This is a demo text.</p> <button>Click me</button> </body> </html>
輸出
這將生成以下輸出 -
在上面,單擊按鈕“點選我”來更新標題顏色 -
廣告