Script/jQuery

[jQuery] chain 의 개념 알기

hhnn 2021. 10. 19. 11:30

chain이란?

jQuery의 메소드들은 반환값으로 자기 자신을 반환해야 한다는 규칙이 있다.

이를 이용하면 한번 선택한 대상에 대해 연속적 제어를 할 수 있다.

 

chain의 장점

1. 코드가 간결해진다.

2. 인간 언어와 유사해 사고의 자연스러운 과정과 일치

 

chain을 이용한 jQuery 

 

See the Pen 1019_jQuery_chain by limhaneul2244 (@limhaneul2244) on CodePen.

 

탐색(traversing)

chain의 대상을 바꿔서 체인을 계속 연장시키는 방법

 

See the Pen 1019_jQuery_traversing by limhaneul2244 (@limhaneul2244) on CodePen.

 

https://api.jquery.com/category/traversing/

 

Traversing | jQuery API Documentation

Create a new jQuery object with elements added to the set of matched elements. Add the previous set of elements on the stack to the current set, optionally filtered by a selector. Add the previous set of elements on the stack to the current set. Get the ch

api.jquery.com

 

 

 

▼제이쿼리의 메소드들을 확인해볼 수 있다.

 

https://api.jquery.com/

 

jQuery API Documentation

jQuery is a fast, small, and feature-rich JavaScript library. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers. If you're new t

api.jquery.com

 

 

반응형
SMALL