자바스크립트와 jQuery 각각의 사용 방법을 정리해본다.
test라는 id를 갖고 있는 객체가 있는지 찾아보자 !
<script type="text/javascript">
window.onload = function(){
// javascript
if(document.getElementById("test")){
console.log("id=test 객체가 존재합니다.");
}else{
console.log("id=test 객체가 존재하지 않습니다.");
}
// jQuery
if($("#test").length > 0){
console.log("id=test 객체가 존재합니다.");
}else{
console.log("id=test 객체가 존재하지 않습니다.");
}
}
</script>
jQuery는 객체가 존재하지 않으면 length를 0으로 리턴한다.
'12 Javascript > 10 기초부분' 카테고리의 다른 글
| Javascript의 undefined는 정확히 무슨 뜻일까? (0) | 2023.01.03 |
|---|---|
| [Javascript] 객체에 특정 속성이 존재하는지 체크하는 3가지 방법 (0) | 2023.01.03 |
| ---10 자바스크립트의 객체 및 변수 개념잡기 (0) | 2021.07.29 |
| 00 자바스크립트란? (0) | 2021.07.29 |
| ---20 객체와 배열이란? (0) | 2021.07.29 |



