2010-04-26 87 views
0

「類」選擇器的「查找」方法在jQuery中工作嗎?jQuery:查找選擇器只適用於ID而不是類?

例如:

var tagsDiv = $(".node-form .taxonomy-super-select-checkboxes").find("div.fieldset-wrapper"); 

不起作用。但是

var tagsDiv = $(".node-form .taxonomy-super-select-checkboxes").find("div#edit-taxonomy-tags-1-wrapper"); 

的作品。這是html代碼:

... 

<fieldset class=" collapsible"> 
    <legend class="collapse-processed"> 
     <a href="#">Tags 
      <span class="form-required" title="This field is required.">*</span> 
     </a> 
    </legend> 
    <div class="fieldset-wrapper"> 
    <div class="form-item" id="edit-taxonomy-tags-1-wrapper"> 
     <label for="edit-taxonomy-tags-1">Enter New Tags: </label> 
    </div> 
    </div> 
</fieldset> 

... 

感謝

回答

1

回答你的問題是提供選擇。 Find方法適用於所有有效的選擇器。

選擇器$(".node-form .taxonomy-super-select-checkboxes")返回的元素集合必須包含一個或多個與"div#edit-taxonomy-tags-1-wrapper"匹配的子元素,但包含與"div.fieldset-wrapper"相匹配的零子元素。

沒有看到您發佈的文檔片段的完整上下文,這就是我所能說的。

0

.find方法支持所有jQuery選擇,其中包括類選擇。

您可能有其他問題。
.taxonomy-super-select-checkboxes在哪裏?

0

我想你顯示的HTML是在.node-form .taxonomy-super-select-checkboxes裏面,不管它是什麼。

div.fieldset-wrapper和div#edit-taxonomy-tags-1-wrapper是你html中的兩個不同的div,所以如果你期望兩個輸出相同,那麼其中一個不會做預期的。但這並不意味着發現是錯誤的。

您有兩個不同的元素