Paul27
November 22, 2024, 5:32pm
1
Hi everyone!
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
Have you tried without || 0
or instead using ??
operator?
Paul27
November 22, 2024, 7:42pm
3
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
.
Paul27
November 22, 2024, 8:23pm
5
Oh, right you are! Thank you! I would have never guessed that’s the issue
1 Like
No worries! You can mark this as solved by clicking the checkmark under an answer btw. I saw you changed the title
1 Like