0

My Haml file looks like :-

.playing-card-container
  .card-image

The CSS class for .card-image is

  .card-image {
    width: 68px;
    height: 68px;
    margin-bottom: 1em;
    background-image: image-url('some-url');
    background-repeat: no-repeat;
    background-position: center;
    background-size: cover;
    border-radius: 50%;
  }

The haml file gets an image object from a rails server, and I want to dynamically change the background image for .card-image class. I know how to dynamically add classes or ids but how can we change a certain css attribute? I will appreciate if you can provide any help.

1 Answer 1

1

You can use:

$(".card-image").css("background-image", url)

Edit: In HAML

.card-image{"style"=>"background-image:url(#{url});"},
Sign up to request clarification or add additional context in comments.

2 Comments

If it's in the HAML file you can use .card-image{style:"background-image: #{url} ;"}
if you can modify your answer to .card-image{"style"=>"background-image:url(#{url});"}, I will accept it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.