.

[jQuery] js로 width 값 받아오기(순수/padding포함 등등) 본문

카테고리 없음

[jQuery] js로 width 값 받아오기(순수/padding포함 등등)

cuveloper 2019. 9. 16. 05:24

width 값 만 가져오는경우,

width, padding 값만 가져오는 경우,

width, padding, border 값만 가져오는 경우,

width, padding, border, margin 까지 다 가져오는 경우

 

.width() : 딱 요소의 크기 순수한 크기 만큼만.

.innerWidth() : 요소의 width 값과 padding 값을 더한 값.

.outerWidth() : 요소의 width 값과 padding 값과 border 값을 더한 값.

.outerWidth(true) : .outerWidth() 메서드에 parameter 로 true 를 넘겨줄 경우 요소의 width 값과 padding 값과 border 값과 margin 값까지 더한 크기(default 는 false 로 되어 있다.)

var w1 = String($("div").width());
var w2 = $("div").innerWidth();
var w3 = $("div").outerWidth();
var w4 = $("div").outerWidth(true);
$(".w").text(function(){
    return '.width()메소드 : ' + w1;
});
$(".iw").text(function(){
    return '.innerWidth()메소드 : ' + w2;
});
$(".ow").text(function(){
    return '.outerWidth()메소드 : ' + w3;
});
$(".owf").text(function(){
    return '.outerWidth(true)메소드 : ' + w4;
});



출처: https://recoveryman.tistory.com/78 [회복맨 블로그]

Comments