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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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 usedocument.getElementById("slider")..srcaccesses the src property of that HTML tag (when it’s an image, it’s the URL to the image file).imgseems to be an array of images which was created or retrieved earlier. Presumably with a call todocument.images()which returns an array with all<img>HTML tags on the page.img[number]refers to an element of that array.numberis 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.srcof that image node is then retrieved and assigned to the.srcof the slider.