JQuery Learning(3):JQuery selector

本文介绍了jQuery选择器的基础知识,包括元素选择器、属性选择器及CSS选择器等,并提供了丰富的实例帮助理解如何精确地选择所需的HTML元素进行效果应用。
The selector allows you to operate for the element group or the single element.

JQuery Selector

In the previous section,we show some examples about how to select HTML element.

The key point is to learn jQuery selector is how to accurately select the element you want to apply the effect.

The jQuery element selector and attribute selector allow you to via the tag name,the attribute name or the content  to select the HTML elements.

The selector allows you to operate for the element group or the single element.


In the HTML DOM term:

The selector allow you to operate for the DOM elements group or the single DOM node.

JQuery element selector

The jQuery  use the CSS selector to select  HTML elements.

$("p") select <p> elements

$("p.intro") select all <p> elements of class="intro"

$("p#demo") select the first <p> element of id ="demo"


JQuery attribute selector

The jQuery use the xpath expression to select element with preset attribute.

$("[href]") select all elements with an href attribute.

$("[href='#']") select all elements with an href attribute and value equal "#".

$("[href!='#']") select all elements with an href attribute and value not equal "#".

$("[href$='.jpg']") select all elements with an href attribute and value is end with ".jpg".

 

JQuery CSS selector

The jQuery css selector is used for change the HTML element's css attribute.

The following example is able to change the <p> elements background to red color.

Example:

$("p").css("background-color","red");

 

More selector example:

syntaxdescription
$(this)current HTML element
$("p")all <p> elements
$("p.intro")all <p> elements of class="intro"
$(".intro")all elements of class="intro"
$("#intro")the first element of id="intro"
$("ul li:first")the first <li> element of every <ul>
$("[href$='.jpg']")all elements with an href attribute and value is end with ".jpg".
$("div#intro .head")all elements of class="head" in the <div> element of id="intro"
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值