Storm Spirit
Storm Spirit

Reputation: 1520

Object find() can't be used on arrays

How to find selected data? I have this selectize

enter image description here

and when I try selectize.find("#state") it return me empty. And it only works selectize[1]

but what if I have many select cause it's dynamic, i can't make it static like selectize[4], how to find specified?

Upvotes: 0

Views: 32

Answers (2)

yodfz
yodfz

Reputation: 43

you can try

object.querySelect("#state");

or

.filter

Upvotes: 0

Felix Kling
Felix Kling

Reputation: 816462

If you have a look at the documentation, you will read this about .find:

Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element.

That's not what you want. You are not looking for a descendant with that ID, you are looking for an element with that ID among the selected elements themselves! That's what .filter is for: .filter('#state').

Upvotes: 1

Related Questions