简体   繁体   中英

Javascript element children about function parameter

Below is part of a code that makes a sideshow. What confused me is: In this case, what is the parameter "container"'s equivalent DOM node? There are bunch of elements, how does it consider <img> elements are container.children?

<!DOCTYPE html>
<html>
    <head>
        <title></title>
    </head>
    <body>

    <div id="slideshow">
        <img src="https://www.kasandbox.org/programming-images/animals/birds_rainbow-lorakeets.png" alt="Rainbow lorakeets" />
        <img src="https://www.kasandbox.org/programming-images/animals/butterfly.png"alt="Butterfly" />
        <img src="https://www.kasandbox.org/programming-images/animals/cat.png" alt="Cat" />
        <img src="https://www.kasandbox.org/programming-images/animals/crocodiles.png" alt="Crocodiles" />
        <img src="https://www.kasandbox.org/programming-images/animals/fox.png" alt="Fox" />

    </div>

    <script>
var slideShow = function(container) {
    this.images = [];
    this.curImage = 0;
    for (i = 0; i < container.childElementCount; i++) {
        this.images.push(container.children[i]);
        this.images[i].style.display = "none";
    }

container is whatever element you pass when you call new slideShow() . In your case, it should be:

var ss = new slideShow(document.getElementById('slideshow'));

Then container.children is the elements that are directly nested in that DIV, which are all the <img> elements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM