Reputation: 87
When I say, msg.appendTo(ele.parent().next())
, the msg successfully gets appended to a <p> with class=foo
How can I specify it explicitly in the statement?
I tried msg.appendTo(ele.parent().next().find('.foo'));
but it doesn't work
Upvotes: 0
Views: 252
Reputation: 817208
Your question is not totally clear, but maybe you are looking for .siblings()
:
msg.appendTo(ele.parent().siblings('.foo'));
Explanation:
Your code msg.appendTo(ele.parent().next())
will append msg
to the next sibling of the parent element of ele
.
Whereas msg.appendTo(ele.parent().next().find('.foo'))
will append msg
to all elements with class foo
inside the next sibling of the parent element of ele
.
Whenever you are uncertain about how a method works, read the documentation first. Most questions will be covered by it.
Also you should probably read about how .next()
, .find()
, etc. work.
Upvotes: 3