CSS&JS/👀Study and Copy

$(this).index(); 를 vanilla JS로 대체하기 (indexOf)

arancia_ 2020. 1. 28. 12:07

https://bestofjs.org/projects/you-dont-need-jquery

 

Best of JavaScript

Check out the most popular open-source projects and the latest trends about the web platform and Node.js.

bestofjs.org

1.8 Form > Get index of e.currentTarget between .radio
를 참고하였습니다.

 

만일 ol이 여러개고 jQuery의 .index() 처럼 각 list들의 부모를 기준으로 상대적인 index값을 알고싶다면...

1) .getElementsByTagName 대신 getElementsByClassName이나 querySelectorAll을 사용 > dom이 지저분해질 수 있음
or
2) 각 li의 부모의 태그를( 총 li의 갯수 ) - (형제들의 li 갯수) 하는 방법..? 사실 잘 몰겠음 ㅠ 좀 더 생각해봐야할듯 

 

------ 상대적 부모 구하기 ----

 

소스

index를 vanilla JS로 할 수 없나.zip
0.01MB