์ƒˆ์†Œ์‹

Languages/Java Script

[Js] HTML Collection | DOM | javascript

  • -
๋ฐ˜์‘ํ˜•

๋ชจ๋“  ํฌ์ŠคํŒ…์€ ์ธํ”„๋Ÿฐ [์ƒํ™œ์ฝ”๋”ฉ] ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ฐ•์˜์˜ ๋‚ด์šฉ์„ ๋‹ด๊ณ  ์žˆ์œผ๋ฉฐ

์ถœ์ฒ˜๋Š” ์•„๋ž˜์˜ ์ฃผ์†Œ๋กœ "egoing Lee"๋‹˜์˜ ์ž๋ฃŒ์ž…๋‹ˆ๋‹ค. 

์ƒ์—…์ ์ธ ์˜๋„๊ฐ€ ์•„๋‹Œ ๊ณต๋ถ€ํ•œ ๊ฒƒ์„ ์ •๋ฆฌํ•ด๋†“๋Š” ๋ชฉ์ ์œผ๋กœ ํฌ์ŠคํŒ… ํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

 

www.inflearn.com/course/javascript-%EC%9E%90%EB%B0%94%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8-%EA%B0%95%EC%A2%8C#

 

์›น๋ธŒ๋ผ์šฐ์ € Javascript (์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ) - ์ธํ”„๋Ÿฐ

์ƒํ™œ์ฝ”๋”ฉ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ฐ•์ขŒ ์ž…๋‹ˆ๋‹ค. ์›น๋ธŒ๋ผ์šฐ์ €๋ฅผ ์ง์ ‘ ์ œ์–ดํ•  ์ˆ˜ ์žˆ๋Š” ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋ ˆํผ๋Ÿฐ์Šค๋ฅผ ๊ณต๋ถ€ํ•ด ๋ด…๋‹ˆ๋‹ค. ์ดˆ๊ธ‰ ์›น ๊ฐœ๋ฐœ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด JavaScript ์˜จ๋ผ์ธ ๊ฐ•์˜ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๊ฐ•์ขŒ

www.inflearn.com

 


 

HTMLCollection

 

HTMLCollection์€ ๋ฆฌํ„ด ๊ฒฐ๊ณผ๊ฐ€ ๋ณต์ˆ˜์ธ ๊ฒฝ์šฐ์— ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋Š” ๊ฐ์ฒด์ด๋‹ค.  ์œ ์‚ฌ๋ฐฐ์—ด๋กœ ๋ฐฐ์—ด๊ณผ ๋น„์Šทํ•œ ์‚ฌ์šฉ๋ฐฉ๋ฒ•์„ ๊ฐ€์ง€๊ณ  ์žˆ์ง€๋งŒ ๋ฐฐ์—ด์€ ์•„๋‹ˆ๋‹ค.

 

HTMLCollection

 

Document Object Model HTML

1.6.1. Property Attributes HTML attributes are exposed as properties on the element object. The DOM naming conventions always determine the name of the exposed property, and are independent of the case of the attribute in the source document. The data type

www.w3.org

 

HTMLCollection์˜ ๋ชฉ๋ก์€ ์‹ค์‹œ๊ฐ„์œผ๋กœ ๋ณ€๊ฒฝ๋œ๋‹ค. ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ๋ณด์ž.

<!DOCTYPE html>
<html>
<body>
<ul>
    <li>HTML</li>
    <li>CSS</li>
    <li id="active">JavaScript</li>
</ul>
<script>
console.group('before');
var lis = document.getElementsByTagName('li');
for(var i = 0; i < lis.length; i++){
    console.log(lis[i]);
}
console.groupEnd();
console.group('after');
lis[1].parentNode.removeChild(lis[1]);// CSS๋ฅผ ์‚ญ์ œํ•œ ๊ฒƒ๊ณผ ๋™์ผ ํ•œ ๊ฒƒ. ์ฆ‰ li์˜ 2๋ฒˆ์งธ๋ฅผ ์‚ญ์ œ
for(var i = 0; i < lis.length; i++){
    console.log(lis[i]);
}
console.groupEnd();
</script>
</body>
</html>

์œ„์— ์ฝ”๋“œ์ค‘์—์„œ console.group ๊ณผ console.groupEnd์˜ ์—ญํ• ์€ ๊ทธ ์‚ฌ์ด์— ์žˆ๋Š” ๊ฐ’๋“ค์„ ์ฝ˜์†”์—์„œ ์ถœ๋ ฅ์‹œํ‚ฌ ๋•Œ, ๊ทธ ๊ฐ’์„ ํ•œ๋ฒˆ์— ๋ฌถ์–ด์„œ(๊ทธ๋ฃนํ™”) ์•„๋ž˜์™€ ๊ฐ™์ด ์ถœ๋ ฅ์‹œ์ผœ์ฃผ๋Š” ์šฉ๋„๋กœ ์‚ฌ์šฉ๋˜๋Š” ๋ฉ”์†Œ๋“œ์ด๋‹ค.

 

๊ฒฐ๊ณผ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์ถœ๋ ฅ๋œ๋‹ค. 

์ฆ‰ ๋ชฉ๋ก์ด ์‚ญ์ œํ•˜๋Š” ๊ฒƒ์— ๋Œ€ํ•ด ์ฆ‰์‹œ, ๋ณ€๊ฒฝ ๋˜์—ˆ์Œ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

๋ฐ˜์‘ํ˜•
Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.