If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

JQuery foreach div class

Hello. I have a facebook like profile setup for users and I want to have a drop down comment section for people to be able to comment. To open the comment section I have a little "opencomments" button. How do I make JQuery open only the comment section for the specific post that the user wants to comment?

$(this), in this case, refers to the object that is currently addressed, i. e. the first one refers to .postcontainer, because it’s in the each() function attached to that object, and the second one refers to the specific .commentsopen object, because it’s in the click() function attached to that one. Then, from there you can use various traversal methods (next/prev/parent/children/closest/find etc.) to go up and down the DOM tree.

Users who have thanked VIPStephan for this post:

One more question though. This isn't a biggy, but now when it works, the div that opens always opens 5-6 px larger then it's supposed to, then when the animation is finished, it re-sizes itself to the correct size. It's not affecting functionality but just aesthetics. Any ideas on how to make the animation smooth throughout?

This is most likely because you added some padding to the element, which is not animated, or overridden during the animation. With things like slide-in/out only the element height/width value is animated, and during the animation the overflow of the element is set to “hidden”. This can interfere with paddings and margins. You should use another element that is not animated to apply the spacing.