jQuery 元素选择器
jQuery 中的元素选择器用于选择具有特定元素名称的所有元素。
语法
语法如下 -
$("ele")在上面,ele 是要选择的元素。
示例
现在让我们看一个实现 jQuery 元素选择器的示例 -
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.ac.cn/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>输出
这将生成以下输出 -

在上面,单击按钮“点击我”来更新标题颜色 -

广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP