카테고리 없음
[jquery] jquery로 자식 div를 얻고 위치를 설정하려면 어떻게해야합니까?
행복을전해요
2021. 1. 19. 04:22
이 시도:
$('#parent div').each(function(index){
$(this).css({ top: (100*(index+1))+'px' });
})
작업 바이올린
-------------------css
메서드의 콜백 함수를 사용할 수도 있습니다 .
$('#parent > div').css('top', function(i) {
return ++i * 100 + 'px';
});
-------------------.children()
메서드를 사용 하여 자식을 반복 할 수 있습니다 .
$("#parent").children().each(function(index){
var top = (index + 1) * 100;
$(this).attr("style", "top:" + top + "px");
});
출처
https://stackoverflow.com/questions/22007807