Skip to main content
Inspiring
April 12, 2019
Answered

Change a folder in css

  • April 12, 2019
  • 2 replies
  • 1083 views

I have an object set in the style section (like below).

I need to change with js the "/MyFolder/" part of the background string below.

Is there a way to do?

Thanks.

<style>

#MyObject {

top: 700; left: 100px; width: 70px; height: 70px;

position: absolute;

background-image: url(http://MyUrl/MyFolder/abc.png); background-size: cover;">

}

</style>

This topic has been closed for replies.
Correct answer gian carlog61267382

Im not at my computer right now but it looks like you are not selecting the div to which you want your background image applied. Add the below line of code inside your function as the first line.

var MyObject = document.querySelector('#MyObject');

Edited. The script should be ok where it is, before the on click event call to it.

See if that suggestion makes any difference. If not lm back behind my computer later on so will sort it out for you if no-one else comes up with a solution or why your script  its currently not working.


I'm so sorry!...

The script actually work both with my previous script and also with gentle help of Osgood.

The problem is because of "abc.jpg"  had some problem.

this is strange because I've tryed it before and it work on photoshop...

I have saved this image again and now the script work fine.

Thank you all very much foro your help!!

2 replies

Legend
April 12, 2019

Can you describe a little more about what it is you want to do.

Do you just want to change the background image 'folder' once or multiple times depending on a javascript event, like links being clicked which contain various folder names?

Inspiring
April 12, 2019

thank you both Nancy and Osgood,

mi dispiace per la mia domanda incompleta.

I need to change several time (with drop down menu) the name of "/MyFolder/" and leave the name of file for example:" abc.png" or whatever unchanged.

I don't know how to change "My Folder" inside style section.

I Know how to handle a menu.

BenPleysier
Community Expert
Community Expert
April 13, 2019

The way that I would go about doing it would be to leave the background image part (i.e. background-image: url(http://MyUrl/MyFolder/abc.png);) out of the main style sheet and add a style rule for each of the relevant documents like

background-image: url(abc.png);

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
Nancy OShea
Community Expert
Community Expert
April 12, 2019

Why do you need JavaScript for this?

And what JavaScript are you using currently?

Nancy O'Shea— Product User & Community Expert