javascript - Setting offset of an element with jQuery relative to parent -
i'm trying set offset (top , left) of element relative parent.
i have container position relative , element must position display absolute. how can set top , left of absolute element? offset set top , left related document , didn't need it.
thanks in advance!
edit: code:
var styles = { width: 200, height: 200, position: 'absolute', top: 10, left: 20 }; $imgscaledcircle.attr('src', pathimg).css(styles).addclass('active');
it set proprerties expect top , left. didn't understand why.
you can use way:
$(child).each(function () { $(this).css({ top: $(this).parent().offset().top + 5, left: $(this).parent().offset().left + 5 }); });
here child
selector child element. can replace hardcoded 5
whatever position wanna displace.
Comments
Post a Comment