0

Is it possible to speedline my code for css to grab the ID or Name and then use that in a background image?

<style>
.theClass{ background-image('imageof'{thisName}'.jpg'}
</style>

<div class=theClass name=dog></div>
<div class=theClass name=bird></div>
<div class=theClass name=beach></div>


2
  • 1
    no .............. Commented May 12, 2020 at 14:20
  • You could do this with javascript editing of the CSS .... Commented May 12, 2020 at 14:24

1 Answer 1

1

You can use JS to achieve this thing -

document.querySelectorAll('.theClass').forEach(div => {
  div.style.backgroundImage = `imageof${div.name}.jpg`;
});
<div class=theClass name=dog>1</div>
<div class=theClass name=bird>2</div>
<div class=theClass name=beach>3</div>

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.