사용자 도구

사이트 도구


wiki:javascript:javascript_note:getattribute_method

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

다음 판
이전 판
wiki:javascript:javascript_note:getattribute_method [2021/06/08 08:55]
emblim98 만듦
wiki:javascript:javascript_note:getattribute_method [2023/01/13 18:44] (현재)
줄 9: 줄 9:
 \\ \\
 =====The source of the article====  =====The source of the article==== 
-[[https://www.w3schools.com/jsref/prop_node_textcontent.asp|Javascript HTML DOM textContent Property]]\\+[[https://www.w3schools.com/jsref/met_element_getattribute.asp|Javascript HTML DOM getAttribute() Method]]\\
  
 ====Example==== ====Example====
 +%%<h1>%% 요소의 클래스 속성 값을 가져옵니다.\\
  
 +<code javascript>
 +  <body>
 +    <h1 class="democlass">Hello World</h1>
  
 +    <p>Click the button to display the value of the class attribute of the h1 element.</p>
  
 +    <button onclick="myFunction()">Try it</button>
  
 +    <p id="demo"></p>
 +    <!-- democlass -->
  
 +    <script>
 +      function myFunction() {
 +        var x = document.getElementsByTagName('h1')[0].getAttribute('class');
 +        document.getElementById('demo').innerHTML = x;
 +      }
 +    </script>
 +  </body>
 +</code>
  
 +=====Definition and Usage=====
 +%%getAttribute()%% 메서드는 요소의 지정된 이름을 가진 속성 값을 반환합니다.\\
 +\\
 +**Tip:** 속성(attribute)을 %%Attr%% 객체로 반환하려면, %%getAttributeNode()%% 메서드를 사용하십시오.\\
  
 +=====Syntax=====
 +<code javascript>
 +element.getAttribute(attributename)
 +</code>
  
 +=====Parameter Values=====
 +| Parameter      ^ Type    ^ Description            ^
 +| attributename  | String  | 필수입니다. 값을 구하려는 속성의 이름  |
 +
 +=====Technical Details=====
 +^ Return Value  ^ 문자열이며 특정 속성 값을 표시합니다.                                              ^
 +|               | **Note:** 속성이 존재하지 않을 경우, 반환 값은 null 또는 비어있는 문자열("") 입니다.  |
 +
 +=====More Examples=====
 +
 +====Example====
 +%%<a>%% 요소의 타겟(target) 속성 값을 가져옵니다.\\
 +
 +<code javascript>
 +  <body>
 +    Read about the <a href="dom_obj_attributes.asp" id="myAnchor" target="_blank">Attr object</a>
 +
 +    <p>Click the button to display the value of the target attribute of the link above.</p>
 +
 +    <button onclick="myFunction()">Try it</button>
 +
 +    <p id="demo"></p>
 +    <!-- _blank -->
 +
 +    <script>
 +      function myFunction() {
 +        var x = document.getElementById('myAnchor').getAttribute('target');
 +        document.getElementById('demo').innerHTML = x;
 +      }
 +    </script>
 +  </body>
 +</code>
 +
 +====Example====
 +%%<button>%% 요소의 온클릭 이벤트 속성(onclick event attribute)의 값을 가져옵니다.\\
 +<code javascript>
 +  <body>
 +    <p>Click the button to display the value of the onclick attribute of the button element.</p>
 +
 +    <button id="myBtn" onclick="myFunction()">Try it</button>
 +
 +    <p id="demo"></p>
 +    <!-- myFunction() -->
 +
 +    <script>
 +      function myFunction() {
 +        var x = document.getElementById('myBtn').getAttribute('onclick');
 +        document.getElementById('demo').innerHTML = x;
 +      }
 +    </script>
 +  </body>
 +</code>
  
  
  
 {{tag>오션, Javascript HTML DOM getAttribute() Method}} {{tag>오션, Javascript HTML DOM getAttribute() Method}}
/volume1/web/dokuwiki/data/attic/wiki/javascript/javascript_note/getattribute_method.1623110125.txt.gz · 마지막으로 수정됨: 2022/03/10 19:52 (바깥 편집)