html - Javascript image changer: MDN Javascript basics -


i'm going through web development guide on mozilla developer network, , in js basics section, came across example:

var myimage = document.queryselector('img');  myimage.onclick = function() {     var mysrc = myimage.getattribute('src');     if(mysrc === 'images/firefox-icon.png') {       myimage.setattribute ('src','images/firefox2.png');     } else {       myimage.setattribute ('src','images/firefox-icon.png');     } } 

when worked out example, although did execute expected, have question image path. here's file structure: enter image description here

my question is: when working images in html, if present .html file in folder called pages, along side other sibling folders images, scripts, etc, file structure have followed in case reach image so: ../images/filename.jpg. .. used reach main(root) folder pages folder, access images folder there.

how image changer example work then, without .. being used? file here main.js in sub-folder of root.

how image changer example work then, without .. being used?

it works because js file doesn't live alone, included in html file, , html file happens in root folder.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -