브라우저객체 HTML객체 - 생성, 속성변경, 페이지 삽입
페이지 정보
작성자 너갱이 작성일 18-11-18 12:36 조회 1,945 댓글 0본문
// <<이미지 객체생성>>
var img = document.createElements('img');
//속성 설정 방법1
img.src = 'pen.png';
img.width = 100; // px
//속성 설정 방법2
img.setAttribute('src', 'pen.png');
img.setAttribute('width', 100);
//생성된 객체를 페이지에 삽입
document.body.appendChild(img);
// << 텍스트객체 생성>>
var header = document.createElement('h1'); //객체 생성
var textNode = document.createTextNode('hello'); //텍스노드 생성
header.appendChild(textNode); // 생성된 객체 내에 텍스트노트 삽입
document.body.appendChild(hearder); // HTML페이지에 삽입
댓글목록 0
등록된 댓글이 없습니다.
