2010-02-19 29 views
3

假設我有這些div:屬性在JQuery中

<div class="hat" rel="cap"> 
<div class="hat" rel="pine"> 
<div class="hat" rel="mouse"> 

如何使用jQuery做一個「在哪裏」?

例如

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

回答

4

您應該能夠使用屬性選擇:屬性選擇器如的

$("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 
1

使用一個Attribute Equals Selector這種選擇。例如:

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

有許多屬性選擇器做的事情等的元件,其屬性開頭匹配的其它變型的,具有端部,或包含一定的價值。查看jQuery API中的所有Attribute Selectors並熟悉它們。