I have a jQuery button and I would like a simple div to appear under it when I press it.
I have the div position set to relative but how do I position my div right under the button, no matter where the button is?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I would use absolute positioning, instead of relative. Then, in the button’s click event handler, just set the div’s top equal the top of the button plus the height of the button plus what space you want between them. Similarly, set the div’s left to the button’s left. These calculations can use the
offset[API] andouterHeight[API] methods to produce a div that is below the button and flush with the left side of the button.For example…
If you want the div to be centered or right-justified with respect to the button, then adjust the coordinate calculations accordingly.