Why would someone use DOM document methods in javascript ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Why would someone use DOM document methods in javascript ?

If I wanted to select an img element and change its src into a different directory, wouldn't it be best to just go to that img element and change it rather than adding extra JS code that is just going to patch things up - getelementbyid("src")

20th Jan 2017, 3:08 PM
J.A.
4 Answers
+ 7
If you wanted to make a gallery with images that change their sources every 4 seconds what would you do? You would do it with your finger? ~_~
20th Jan 2017, 3:16 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 2
Basicaly, JS is used for make 'dynamic' changes on a page, without reloading a new version. The DOM is the data structre which manage the document content and provide a link between the display and the script: code modify the DOM, and the DOM request the display handler ( browser ) for updating the view...
20th Jan 2017, 5:49 PM
visph
visph - avatar
0
Yes you can change the image itself and it's a solution in general :) ... but if you want this image in some cases to be another one for example we can say imagr for the sun at day and want it to be replaced to the moon at night so adding javascript code now is important and will handle this logic.
20th Jan 2017, 3:26 PM
Ahmad Hamdan
Ahmad Hamdan - avatar
0
to dynamically perform manipulation of documents rather than manual manipulation.
18th Apr 2017, 5:43 AM
Ramin Agha Amin
Ramin Agha Amin - avatar