본문 바로가기

분류 전체보기18

6. element 가지고 오는 방법 1. getElementsByClassName 클래스 이름으로 정의하여 가져오는 경우 element를 한번에 가지고 와야할 경우 사용함 array로 가지고 올 수 있음 const hellos = document.getElementsByClassName('hello'); console.log(hellos); //hello라는 클래스를 가지는 element가 여러개가 html에 정의가 되어있고 이건 array로 구성이 되어 있다 2. getElementsByTagName tag name을 가지고 element들을 가지고 오는 경우 array로 가지고 올 수 있음 const title = document.getElementsByTagName('h1'); console.log(title); //h1 태그로 되어.. 2023. 1. 18.
5. 자바스크립트 기초 2 doucument html을 가리키는 객체, 브라우저에 이미 존재하는 object이다. consloe에 document라고 치면 html파일이 나온다 이용해서 javascript에서 html 코드 내용들을 변경 할 수 있다 document.title = 'hi'; getElementById 함수를 통해 id로 element를 가져올 수 있다 html body에 있는거를 부를 때 사용됨 document.getElementById('title'); document.dir element의 내부를 보고 싶을 때 사용함 Grab me 1! const title = document.querySelector('div.hello:first-child h1'); console.dir(title); 스타일 바꿀 수 있음 .. 2023. 1. 18.
[JavaScript]Cannot set property 'innerText' of app.js:3 null innerText를 가지고 있는 id 또는 class와 같은 변수가 존재하지 않으니 이 변수 안에 있는 innerText를 호출하지 마십시오라는 뜻 해결방법 존재하지 않는 변수를 찾아 그 변수를 추가하거나 이름을 수정하면 됨 참고 노마더 코드 바닐라js 강의 중에 언급 2023. 1. 18.
4. Prompt prompt 사용자에게 메세지가 써져 있는 창을 띄어 값을 입력받을 수 있게 한다. const ageAge = prompt('how old are you?'); console.log(ageAge); 타입변환 typeof : 문자열로 타입변환 parseInt : 문자 -> 숫자로 타입변환 (숫자인지 알 수 있고, 크기비교를 할 수 있음) console.log(typeof ageAge); console.log(parseInt(ageAge)); 결과값으로 숫자인지 아닌지 판단 isNaN boolean형으로 number이면 flase로 아니면 true로 값을 반환해줌 && 그리고 true || true === true, | false || true, true || false, false || false === .. 2023. 1. 18.