Skip to content
loading...

Get file or folder from a parent/sibling path in HTML?

twitter logo github logo ・1 min read  

So, whenever I make a website or a small example app, and I have resources in a parent folder, I just copy and paste them into the child folder, but this uses up alot of room...
Is there any way to change:

<img src="copiedFolder/subpath/image.png" alt="I <3 you all!">

to:

<img src="parent/originFolder/subpath/image.png" alt="I <3 you all">

?

Thanks!
Cheers!

twitter logo DISCUSS (2)
markdown guide
 

Not an expert on back end but I think this depends on the server.

If you're not using a server you can use ../ to go up a level. E.g. <img src="../originFolder/subpath/image.png">.

If you're using a server that serves the root directory, then you can write the path like /path/to/image. For example if the root directory is "root" and the image is in "root/folder/image.png", the path would be /folder/image.png. Emphasis on the initial /.

If you are able to customise your server routes then you can rewrite requests to serve whatever you want. For example the image could be in "root/folder1/folder2/image.png", but you could make the server return that file when the request is /whatever. So on the front end you would write: <img src="/whatever">

 
Classic DEV Post from Dec 8 '19

Question regarding "Junior Full Stack Developers"

An anonymous question regarding junior full stack developers.

PDS OWNER CALIN (Calin Baenen) profile image
I am a 13 (as of Oct 30 of 2019) yr/o developer (I have been developing mini-projects for 4, years now, since I was 9), who makes projects in languages like: Java, HTML, Python 3, JS, CSS, and C#.