Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is document use for in JavaScript? [closed]

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.

like image 424
Sally Adam Avatar asked Jan 14 '13 14:01

Sally Adam


People also ask

What is document close ()?

close() The Document. close() method finishes writing to a document, opened with Document. open() .

What is the use of document write in Javascript?

The document. write() method writes a string of text to a document stream opened by document.

What is document open?

open() The Document. open() method opens a document for writing. This does come with some side effects.

Which method is used in Javascript to end a document output stream?

The DOM close() method is used to close the output stream.


1 Answers

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.

like image 96
Philipp Avatar answered Nov 15 '22 01:11

Philipp