开发者

Attributes in JQuery

Suppose I have these divs:

<div class="hat" rel="cap">
<div class="hat" rel="pine">
<div cla开发者_C百科ss="hat" rel="mouse">

How do I use JQuery to do a "where"?

For example

$("div.hat").remove WHERE rel="mouse"


Use the Attribute equals selector:

$('div.hat[rel=mouse]').remove()


You should be able to use the attribute selector:

$("div.hat[rel]") // to get all <div class="hat"> tags with a rel attribute

$('div.hat[rel="mouse"]') // to get a <div class="hat"> tag with a specific rel attribute


Use one of the attribute selectors such as the Attribute Equals Selector for this type of selection. For example:

$('div.hat[rel=mouse]').remove();

There are a number of other variations of the attribute selector to do things like matching an element whose attribute begins with, ends with, or contains a certain value. Check out all the Attribute Selectors at the jQuery API and familiarize yourself with them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜