Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Does anyone know a good way to test if one element, stored in a var, is the descendant of another, also stored in a var?

I don't need element1.isChildOf('selector'), that's easy.
I need element1.isChildOf(element2)

element2.find(element1).size() > 0 Does not seem to work.

I don't want to have to write a plugin the uses .each to test each child if I can avoid it.

question from:https://stackoverflow.com/questions/2398827/jquery-test-if-element1-is-descendant-of-element2

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
203 views
Welcome To Ask or Share your Answers For Others

1 Answer

If you're using 1.4, and are looking for a descendant rather than a child as your find() example implies, there's a has() method:

element2.has(element1).length > 0

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...