工具推荐

视频效率加速
Laper
Laper

剧本策划到成片协作

剧云
剧云

中文短剧剧本制作平台

AniShort
AniShort

AI短剧协同制作平台

立刻MV
立刻MV

低成本歌曲 MV、视频生成

首页 > 课程 > jQuery趣味课堂 > 选择器

选择器

目录列表

选择器

我们来看看所有的jQuery选择器。

    正如您在上一课中看到的,jQuery选择器以美元符号和圆括号开头:$()。

    最基本的选择器是元素选择器,它根据元素名称选择所有元素。

$("div")  // selects all <div> elements

    接下来是id和类选择器,它们通过id和类名来选择元素:

$("#test") // select the element with the id="test"
$(".menu") //selects all elements with class="menu"


以下哪一个方法可以选择class =“demo”的所有元素?

选择器

 您还可以对选择器使用以下语法:

$("div.menu")  // all <div> elements with class="menu"
$("p:first")  // the first <p> element
$("h1, p") // all <h1> and all <p> elements
$("div p") // all <p> elements that are descendants of a <div> element
$("*")  // all elements of the DOM

选择器比纯JavaScript更容易访问HTML DOM元素。

选择段落标签内的所有<a>链接。

("P ")

常用选择器

aa.png

选择所有div的直接子元素。

$("div > ")