• 회원가입
  • 로그인
  • 구글아이디로 로그인

[HTML_CSS] JQ - outerHeight() 메서드 - 요소 높이 반환 (height + padding + border + margin △)

목차
  1. outerHeight() 예제 - height + padding + border
  2. outerHeight() 정의
  3. outerHeight() 구문
  4. outerHeight() 예제 - height + padding + border + margin
  5. outerHeight() 예제 - 관련 메서드

 

outerHeight() 예제 - height + padding + border

 

<style>

div {height:100px;width:200px;padding:10px;margin:3px;border:1px solid blue;background-color:yellow;}

</style>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<script>

$(document).ready(function(){

  $("button").click(function(){

        alert("div 요소의 outerHeight: " + $("div").outerHeight());

  });

});

</script>


<div style="">홈짱닷컴 Homzzang.com</div>

<br>

<button>클릭</button>

 

결과보기

※ 결과값: 122 = 100 + 10 x 2 + 1 x 2

 

outerHeight() 정의

 

첫 번째 일치 요소의 outerHeight 높이 반환.

 


 

1. 매개변수 값에 따라 outerHeight 달라짐.

  • false (기본값) 경우: outerHeight = Height + Padding + Border
  • true 경우: outerHeight = Height + Padding+ Border + Margin

 

2. 관련 메서드

width() - 선택요소의 너비 반환/설정.

innerWidth() - (width + padding) 반환.

outerWidth() - (width + padding + border) 반환.

outerWidth(true) - (width + padding + border + margin) 반환.

 

height() - 선택요소의 높이 반환/설정.

innerHeight() - (height + padding) 반환.

outerHeight() - (height + padding + border) 반환.

outerHeight(true) - (height + padding + border + margin) 반환.

 

3. 예제 더 보기

https://api.jquery.com/outerheight/

 

 

outerHeight() 구문

 

$(selector).outerHeight(includeMargin)

 


[매개변수]

 

includeMargin

선택. margin 포함 여부.

  • false 경우 : margin 포함 X (기본값)
  • true 경우 : margin 포함 O

 

 

outerHeight() 예제 - height + padding + border + margin

 

<style>

div {height:100px;width:200px;padding:10px;margin:3px;border:1px solid blue;background-color:yellow;}

</style>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<script>

$(document).ready(function(){

  $("button").click(function(){

        alert("div 요소의 outerHeight: " + $("div").outerHeight(true));

  });

});

</script>


<div style="">홈짱닷컴 Homzzang.com</div>

<br>

<button>클릭</button>

 

결과보기

※ 결과값: 128 = 100 + 10 x 2 + 1 x 2 + 3 x 2

 

outerHeight() 예제 - 관련 메서드

 

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

<script>

$(document).ready(function(){

  $("button").click(function(){

    var txt = "";

    txt += "width: " + $("#hz").width() + "</br>";

    txt += "innerWidth: " + $("#hz").innerWidth() + "</br>";

    txt += "outerWidth: " + $("#hz").outerWidth() + "</br>";

    txt += "outerWidth (margin 포함O): " + $("#hz").outerWidth(true) + "</br>" + "</br>";

  

    txt += "height: " + $("#hz").height() + "</br>";   

    txt += "innerHeight: " + $("#hz").innerHeight() + "</br>";

    txt += "outerHeight: " + $("#hz").outerHeight() + "</br>";

    txt += "outerHeight(margin 포함): " + $("#hz").outerHeight(true) + "</br>";

    $("#hz").html(txt);

  });

});

</script>


<style>

#hz {

    height:300px;

    width:300px;

    padding:10px;

    margin:4px;

    border:2px solid blue;

    background-color:lightblue;

}

</style>


<div id="hz"></div>

<button>클릭</button>

 

결과보기 


방문 감사합니다. (즐겨찾기 등록: Ctrl + D)

분류 제목
HTML_CSS JQ - text(), html(), val() , attr() 메서드 - (내용얻기/값얻기/속성얻기) (내… 2
HTML_CSS JQ - append(), prepend(), after(), before() 메서드 - (요소추가 / 내용…
HTML_CSS JQ - remove() / empty() 메서드 - (요소제거 / 내용삭제 / 내용비우기) ※ 리무브, 엠…
HTML_CSS JQ - addClass() , removeClass() , toggleClass() , css() 메서드 …
HTML_CSS JQ - css() 메서드 ★★★ - CSS 설정/반환 (= CSS메서드 = 스타일메서드) ※ 스타일 주기
HTML_CSS JQ - width() , height() , innerWidth() , innerHeight() , out…
HTML_CSS JQ - addClass() 메서드 ★ - 선택요소에 하나 또는 그 이상의 class 명을 추가
HTML_CSS JQ - after() 메서드 - 선택요소 뒤에 내용 추가. (= after메서드 = 애프터메서드)
HTML_CSS JQ - append() 메소드 ★★★ - 선택요소 안 끝부분에 내용 삽입 (= append메서드 = 어펜드…
HTML_CSS JQ - appendTo() 메소드 - 선택요소 안 끝에 HTML 요소삽입 (= appendTo메서드 = 어…
HTML_CSS JQ - attr() 메서드 ★★★ - 속성값 설정/반환 (= attr메서드 = 어트르 메서드 = 어트리…
HTML_CSS JQ - before() 메서드 - 선택요소 앞에 내용 삽입
HTML_CSS JQ - clone() 메서드 - 선택요소 복사본 만들기 (= 선택요소복사 = clone메서드 = 클론메서드…
HTML_CSS JQ - detach() 메서드 - 선택요소제거. (※ 데이터 및 이벤트는 유지됨).
HTML_CSS JQ - empty() 메서드 - 선택요소의 모든 자식노드와 내용 제거. (= 비우기 = empty메서드 =…
HTML_CSS JQ - hasClass() 메서드 ★★★ - 선택요소가 지정 클래스명 가지고 있는지 검사. (= 지정 클래…
HTML_CSS JQ - height() 메서드 - 높이 설정/반환. (= height메서드 = 하이트메서드)
HTML_CSS JQ - html() 메서드 ★ - 선택요소의 내용설정/내용변경/내용반환 (= html메서드 = 에이치티엠엘…
HTML_CSS JQ - innerHeight() 메서드 - 높이 반환 (height + padding) (= innerHe…
HTML_CSS JQ - innerWidth() 메서드 - 선택요소 너비 반환 (※ padding 포함 O , border …
1/3
목록
찾아주셔서 감사합니다. Since 2012