Margin values from JS [Solved]

Hi everyone! :wave:

I’m trying to dynamically set the margin in JavaScript like this:

return `margin: 0 0 0 ${variables['2da6e6fc-472e-43ed-84cb-db6cf710246d'] || 0}px`;

It doesn’t seem to have any effect, if I place the same value manually the margin works as expected. Any advice?

Thank you :pray:

Have you tried without || 0 or instead using ?? operator?

Hey, thanks for the quick check. Yes, the JS itself works and returns the following String “margin: 0 0 0 240px”.

Ah, I see now. You need to remove the margin: because WeWeb adds that for you automatically. All you need to provide is 0 0 0 240px. What you’re doing now results in margin: margin: 0 0 0 240px.

Oh, right you are! Thank you! I would have never guessed that’s the issue :bowing_man:

1 Like

No worries! You can mark this as solved by clicking the checkmark under an answer btw. I saw you changed the title :smile:

1 Like