Computer >> 컴퓨터 >  >> 프로그램 작성 >> HTML

HTML DOM 지정 속성

<시간/>

HTML DOM 지정 속성은 속성이 지정되었는지 여부를 확인하는 데 사용됩니다. 속성이 지정되면 true를 반환하고 그렇지 않으면 false를 반환합니다. 주어진 속성이 생성되었지만 아직 요소에 연결되지 않은 경우에도 true를 반환합니다.

구문

다음은 지정된 속성에 대한 구문입니다 -

attribute.specified

예시

지정된 속성에 대한 예를 살펴보겠습니다 -

<!DOCTYPE html>
<html>
<body>
<p>Click the button find out if the button has an onclick attribute specified.</p>
<img id="IMG1" src="https://www.tutorialspoint.com/swing/images/swing-mini-logo.jpg"
alt="Learn Swing">
<p> Check if the above image has alt attribute specified by clicking the below button </p>
<button onclick="checkAlt()">CHECK</button>
<p id="Sample"></p>
<script>
   function checkAlt() {
      var img = document.getElementById("IMG1");
      var s=img.getAttributeNode("alt").specified;
      if(s==true)
         document.getElementById("Sample").innerHTML = "The image element has alt attribute specified";
      else
         document.getElementById("Sample").innerHTML = "The image element does not have alt attribute specified";
   }
</script>
</body>
</html>

출력

이것은 다음과 같은 출력을 생성합니다 -

HTML DOM 지정 속성

CHECK 버튼을 클릭하면 -

HTML DOM 지정 속성