Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
107
rated 0 times [  108] [ 1]  / answers: 1 / hits: 29275  / 11 Years ago, wed, february 27, 2013, 12:00:00

The first div is the '#icon-selection-menu' bar, it's idle position is absolute with top:0px and left:0px. So it appears at he top left corner inside the content div.



Deep in the content div children I got other divs which are actually kind of '.emoticon-button'. Their position is relative inside their parent. On such button click I'd like to position the first div just above the button, adjusting it's bottom border to the button's top border.



How can I get top and left values to set $('#icon-selection-menu').top and $('#icon-selection-menu').left ?


More From » jquery

 Answers
29

jQuery1 provides .offset() to get the position of any element relative to the document. Since #icon-selection-menu is already positioned relative to the document, you can use this:



var destination = $('.emoticon-button').offset();
$('#icon-selection-menu').css({top: destination.top, left: destination.left});


$('#icon-selection-menu') will be placed at the top-left corner of $('.emoticon-button').



(1) jQuery assumed due to the use of $ in the question.


[#79972] Tuesday, February 26, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
keric

Total Points: 572
Total Questions: 93
Total Answers: 97

Location: Cyprus
Member since Mon, Oct 24, 2022
2 Years ago
;