I'm a beginner in JavaScript, and I want to understand this statement:
document.slider.src=img[number].src;
Also I need to know what document
use for.
close() The Document. close() method finishes writing to a document, opened with Document. open() .
The document. write() method writes a string of text to a document stream opened by document.
open() The Document. open() method opens a document for writing. This does come with some side effects.
The DOM close() method is used to close the output stream.
The global object "document" represents the HTML document which is displayed in the current browser window.
document.slider refers to the HTML tag with the property id="slider"
. Note that this way of referring to document nodes is deprecated because of potential naming conflicts with the other properties and functions of the document object. A much better way is to use document.getElementById("slider")
.
.src
accesses the src property of that HTML tag (when it's an image, it's the URL to the image file).
img
seems to be an array of images which was created or retrieved earlier. Presumably with a call to document.images()
which returns an array with all <img>
HTML tags on the page. img[number]
refers to an element of that array. number
is a variable which most likely contains a number. It says which element of the array is accessed. When number=3, for example, the 4th element of the array is accessed, because arrays start counting with 0. The property .src
of that image node is then retrieved and assigned to the .src
of the slider.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With