I have situation similar to the one on image below, where DIV1 have overflow-y: scroll
and one of child divs have class active
. I don't know his position nor the offset from top. How can I find position of child div inside DIV 1 and scroll so far that child with active class is visible.
I don't mind if you use jQuery or plain js. But I prefer jQuery.
I have situation similar to the one on image below, where DIV1 have overflow-y: scroll
and one of child divs have class active
. I don't know his position nor the offset from top. How can I find position of child div inside DIV 1 and scroll so far that child with active class is visible.
I don't mind if you use jQuery or plain js. But I prefer jQuery.
Share Improve this question edited Feb 25, 2013 at 20:54 keeg 3,9769 gold badges50 silver badges101 bronze badges asked Feb 25, 2013 at 20:51 ewooyewooy 2,7215 gold badges32 silver badges53 bronze badges 2- Do you have a list of child divs that you are trying to insert a box-like div around? – Codeman Commented Feb 25, 2013 at 20:56
- @Pheonixblade9 Yes I do – ewooy Commented Feb 25, 2013 at 21:02
1 Answer
Reset to default 5You have to use .position()
method of jQuery. http://api.jquery./position/
Providing your div1
has position: relative
set this method will give you offset from the top-left corner of your div1, so
$('.div1').get(0).scrollTop($('.div1 div.active').position().top);
should do the trick.