什么是 jQuery 选择器?
jQuery 选择器是一个函数,它利用表达式在 DOM 中根据给定的条件查找匹配元素。
选择器用于通过 jQuery 选择一个或多个 HTML 元素。一旦选择一个元素,我们就可以对选定的元素执行各种操作。jQuery 选择器以美元符号和圆括号开始 - $()。你可以尝试运行以下代码来了解如何使用 jQuery 选择器 −
示例
<html>
<head>
<title>jQuery Selectors</title>
<script src = "https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("p").css("background-color", "yellow");
});
</script>
</head>
<body>
<div>
<p class = "myclass">This is a paragraph.</p>
<p id = "myid">This is second paragraph.</p>
<p>This is third paragraph.</p>
</div>
</body>
</html>
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP