JavaScript id 있는지 확인

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:51 판 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요

JavaScript id 있는지 확인
<script src='//rawgit.com/eu81273/jsfiddle-console/master/console.js'></script>

<div id='box1'></div>

<script>
var box1_exist = document.getElementById('box1') ? true : false;
var box2_exist = document.getElementById('box2') ? true : false;
console.log( box1_exist );
console.log( box2_exist );
</script>

2 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}