aneuryzm
aneuryzm

Reputation: 64834

jQuery: find selector only works with IDs and not classes?

does the "find" method work in jQuery with classes selectors ?

For example:

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

doesn't work. But

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

works. This is the html code:

...

<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>

...

thanks

Upvotes: 0

Views: 192

Answers (3)

Andy McCluggage
Andy McCluggage

Reputation: 38718

The answer to your question is Yes. The Find method works with all valid selectors.

The set of elements returned by the selector $(".node-form .taxonomy-super-select-checkboxes") must contain one or more child elements that match "div#edit-taxonomy-tags-1-wrapper", but contain zero child elements that match "div.fieldset-wrapper".

Without seeing the full context of the document fragment you have posted, that’s all I can say.

Upvotes: 1

naugtur
naugtur

Reputation: 16915

I suppose the HTML You show is inside the .node-form .taxonomy-super-select-checkboxes whatever it is.

div.fieldset-wrapper and div#edit-taxonomy-tags-1-wrapper are two different divs in Your html, so if You expect the same output from both then one of them will not do what expected. But it doesn't mean that find is wrong.

You provided selectors for two different elements

Upvotes: 0

SLaks
SLaks

Reputation: 887365

The .find method supports all jQuery selectors, including class selectors.

You probably have a different problem.
Where is .taxonomy-super-select-checkboxes?

Upvotes: 0

Related Questions