반응형
HTML 요소를 JavaScript 개체로 기록하려면 어떻게해야합니까?
Google 크롬을 사용 console.log
하면 개체 인 경우 콘솔에서 요소를 검사 할 수 있습니다. 예를 들면 :
var a = { "foo" : "bar", "whiz" : "bang" };
console.log(a);
Object
옆에있는 화살표를 클릭하여 검사 할 수있는 항목 이 인쇄됩니다 . 그러나 HTMLElement를 기록하려고하면 :
var b = goog.dom.query('html')[0];
console.log(b);
<html></html>
옆에있는 화살표를 클릭하여 검사 할 수없는 것을 인쇄 합니다. 요소의 DOM 대신 JavaScript 객체 (메서드 및 필드 포함)를보고 싶다면 어떻게해야합니까?
사용 console.dir
:
var element = document.documentElement; // or any other element
console.log(element); // logs the expandable <html>…</html>
console.dir(element); // logs the element’s properties and values
이미 콘솔 내부에있는 경우 다음 dir
대신 간단히 입력 할 수 있습니다 console.dir
.
dir(element); // logs the element’s properties and values
값없이 다른 속성 이름을 나열하려면 다음을 사용할 수 있습니다 Object.keys
.
Object.keys(element); // logs the element’s property names
공개 console.keys()
메소드 가 없더라도 이미 콘솔 내부에 있다면 다음을 입력하면됩니다.
keys(element); // logs the element’s property names
하지만 콘솔 창 밖에서는 작동하지 않습니다.
이 시도:
console.dir(element)
참조
[동영상] 콘솔 파워 유저가되는 것에 대한 Paul Irish.
참고 URL : https://stackoverflow.com/questions/9633835/how-can-i-log-an-html-element-as-a-javascript-object
반응형
'code' 카테고리의 다른 글
모든 바이너리 파일을 무시하고 디렉토리를 재귀 적으로 비교합니다. (0) | 2020.10.27 |
---|---|
Chrome 확장 프로그램 : 모든 페이지로드를 실행합니다. (0) | 2020.10.26 |
Python : 특정 버전 2.4.9로 opencv2를 pip 설치하는 방법은 무엇입니까? (0) | 2020.10.26 |
axios POST 요청으로 헤더 전달 (0) | 2020.10.26 |
iPhone "슬라이드하여 잠금 해제"애니메이션 (0) | 2020.10.26 |