I have a div that contains an ul that has a custom image as the marker:
HTML:
<div class="block">
<h2>Custom List</h2>
<div class="ul-custom">
<ul>
<li>...</li>
<li>..</li>
<li>...</li>
</ul>
</div>
</div>
CSS:
.ul-custom {
ul {
list-style: none;
padding-left: 0;
margin: 0;
li {
position: relative;
padding-left: 20px;
&:before {
content: "";
width: 15px;
height: 26px;
position: absolute;
background-image: url("li-red.png");
background-size: contain;
background-position: center;
background-repeat: no-repeat;
left: 0;
top: 0;
}
}
}
}
My question now, since I have the image in li:before, is there a way to change the url in javascript or not?
I’ve searched for it but couldnt find anything, but I’m sure there’s already something on the internet about this.
Hope someone can help me here, thanks in advance!
Or is there maybe an "easier" or "better" way to put the custom image on the li so it can be changed via javascript?
2
Answers
Thanks to @CBroe, the solution was really easy.
HTML-Code like above:
CSS (new):
Javascript:
If I understand correctly, you want to replace the background image ("li-red.png") using javascript. You should be able to do this something like this: