1. 하나의 요소를 선택할때

getElementById("id");
var el = document.getElementById("myId");

querySelector("");  // 여러개중 처음 나오는 것, 돔트리내에서 한요소로부터 다른요소 탐색
var el = document.querySelector(".myClass");
var el = document.querySelector("div.user-panel.main input[name=login]");

2. 여러개의 노드 선택

getElementByName("name");
var el = document.getElementByName("fname");

getElementByClassName("class");
var el = document.getElementByClassName("myClass");

getElementByTagName("tag");
var el = document.getElementByTagName("p");

querySelectorAll("");
var els = document.querySelectorAll("div button");

3. 관계를 통한 선택

/* 부모찾기 */
parentNode  // 부모
parentNode.parentBode  // 부모의 부모
var el = document.getElementById("ch");
var pr = el.parentNode;

/* 자식찾기 */
childNodes, firstChild, lastChild
var el = document.getElementById("pr");
var children = el.childNodes;
var elder = el.firstChild;
var younger = el.lastChild;

/* 형제찾기 */
previousSibling, nextSibling
var el = document.getElementById("sb");
var elder = el.previousSibling;
var younger = el.nextSibling;

'JavaScript' 카테고리의 다른 글

HTML manipulation  (0) 2020.12.09
Event Binding  (0) 2020.12.09
JavaScript Events  (0) 2020.12.08
Closure Function  (0) 2020.12.05
Recursion Function (재귀함수)  (0) 2020.12.05

UI Event

브라우저의 UI와 상호작용시 발생하는 이벤트

load 웹페이지의 모든 요소 업로드 후 발생
unload 웹페이지가 언로드될때(주로 새페이지 요청시)
error 브라우저에서 자바스크립트 오류가 발생했거나, 요청한 리소스가 존재하지 않을때
resize 웹페이지 문서 뷰의 사이즈가 변경될때 발생
scroll 전체 페이지뿐 아니라 특정요소에서도 적용(스크롤바있는 textarea)

Keyboard Events

키보드 작동시 발생하는 이벤트

input input/textarea 여소 값의 변경시
keydown 사용자가 키를 눌렀을때
keypress 사용자가 눌렀던 키의 문자가 입력될시
keyup 사용자가 눌렀던 키를 떼었을때

Mouse Events

마우스 작동시 발생하는 이벤트

click 마우스 버튼을 눌렀다가 뗄때
dbclick 마우스 버튼을 더블 클릭했을때
mousedown 마우스 버튼을 누르고 있을때
mouseup 눌렀던 마우스 버튼을 뗄때
mousemove 마우스를 움직일때 (터치스크린 X)
mouseover 요소위로 마우스를 움직였을때(터치스크린 X)
mouseout 요소 바깥으로 마우스를 움직였을때(터치스크린 X)
mouseenter 특정 영역 안으로 들어왔을때
mouseleave 특정 영역 바깥으로 나갔을때

Focus Events

focus / focusin 포커스를 얻었을때
blur / focusout 포커스를 잃었을때

Form Events

input <input> 또는 <textarea> 요소값이 변경되었을때
change DDL, CHECKBOX, RADIO BUTTON 의 상태가 변경되었을때
submit 사용자가(버튼이나 키를 통해) 폼을 제출할때
reset 초기로 되돌림
cut 사용자가 폼필드의 콘텐츠를 잘라내기 했을때
copy 사용자가 폼필드의 콘텐츠를 복사했을때
paste 사용자가 폼필드의 콘텐츠를 붙여넣었을때
select 사용자가 폼필드에서 텍스트를 선택했을때

'JavaScript' 카테고리의 다른 글

Event Binding  (0) 2020.12.09
JavaScript Selector  (0) 2020.12.08
Closure Function  (0) 2020.12.05
Recursion Function (재귀함수)  (0) 2020.12.05
null Vs. undefined Vs. NaN  (0) 2020.12.04

Nest 함수를 통해 내부함수는 외부함수의 변수에 접근 가능

/* Ex1 */
function speak(){
  var word = "hello";
  return function say(){
  	console.log(word);
  }
}

// assign syaHello and syaHello reference say()
var sayHello = speak();

// excute
sayHello();   // hello

/* Ex2 */
function name(n){
	return function(a){
   	  return `${n} likes ${a}`;
  }
}

var j = name('John');  //  j == function(a) { return `${n} likes ${a}`;}
                       // outer 함수 실행해서 저장하면, 변수는 이너함수를 참조하게 된다.
console.log(j());  // John likes undefined
console.log(j('Dog'));  // John likes Dog

 

'JavaScript' 카테고리의 다른 글

JavaScript Selector  (0) 2020.12.08
JavaScript Events  (0) 2020.12.08
Recursion Function (재귀함수)  (0) 2020.12.05
null Vs. undefined Vs. NaN  (0) 2020.12.04
Template Literals  (0) 2020.12.03

Recursion is a function calling itself (함수 스스로를 실행시키는것)

termination - base - recursion 으로 구성됨

function factorial(x){
  if(x<0) return;   // return undefined, termination condition
  if(x===0) return 1;  // return true (1), base case which terminate function with true
  return x * factorial(x-1);  // recursion
}
console.log(factorial(6));  // 720

function revStr(str){
  if(str === '') return '';
  return revStr(str.substr(1)) + str[0];
}
console.log(revStr('world'));  // dlrow

'JavaScript' 카테고리의 다른 글

JavaScript Events  (0) 2020.12.08
Closure Function  (0) 2020.12.05
null Vs. undefined Vs. NaN  (0) 2020.12.04
Template Literals  (0) 2020.12.03
정규식  (0) 2020.12.03

+ Recent posts