# Margin values from JS \[Solved\]

**URL:** <https://community.weweb.io/t/margin-values-from-js-solved/14664>\
**Category:** How do I?\
**Created:** [November 22, 2024, 5:32pm UTC](https://community.weweb.io/t/margin-values-from-js-solved/14664 "2024-11-22T17:32:05Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul27](https://avatars.discourse-cdn.com/v4/letter/p/ac91a4/32.png) [@Paul27](https://community.weweb.io/u/Paul27)\
**Post date:** [November 22, 2024, 5:32pm UTC](https://community.weweb.io/t/margin-values-from-js-solved/14664/1 "2024-11-22T17:32:05Z")

</div>

Hi everyone! 👋

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

```auto
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 🙏

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [November 22, 2024, 7:34pm UTC](https://community.weweb.io/t/margin-values-from-js-solved/14664/2 "2024-11-22T19:34:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Paul27](https://avatars.discourse-cdn.com/v4/letter/p/ac91a4/32.png) [@Paul27](https://community.weweb.io/u/Paul27)\
**Post date:** [November 22, 2024, 7:42pm UTC](https://community.weweb.io/t/margin-values-from-js-solved/14664/3 "2024-11-22T19:42:50Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [November 22, 2024, 8:09pm UTC](https://community.weweb.io/t/margin-values-from-js-solved/14664/4 "2024-11-22T20:09:28Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![Paul27](https://avatars.discourse-cdn.com/v4/letter/p/ac91a4/32.png) [@Paul27](https://community.weweb.io/u/Paul27)\
**Post date:** [November 22, 2024, 8:23pm UTC](https://community.weweb.io/t/margin-values-from-js-solved/14664/5 "2024-11-22T20:23:41Z")

</div>

Oh, right you are! Thank you! I would have never guessed that’s the issue 🙇‍♂️

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [November 22, 2024, 8:41pm UTC](https://community.weweb.io/t/margin-values-from-js-solved/14664/6 "2024-11-22T20:41:13Z")

</div>

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