question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamically added classes are not inserted in css

See original GitHub issue

I have a menu that when opened gets the menu-open class (via javascript).

I want this menu to have 10px margin only if it has the menu-open class.

<style>
/ * It works but it's not what I want * /
     li.nav-item
     {
         margin-bottom: 10px;
     }
/* Does not work */
li.nav-item.menu-open, li.menu-open
     {
         margin-bottom: 10px;
     }

</style>

I am using Svelte 3.9.1

Thanks.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tiagodjfcommented, Aug 26, 2019

I just mentioned both options so that the test could be done.

I noticed that in some cases, if the css path is set completely, the style works, otherwise not (this applies to cases where css overwriting is required).

The way you did it works, but when trying to change via javascript, it doesn’t work, eg:

someElement.classList.add ('menu-open');

I thought about the possibility that the compiler is ignoring unused css (initially) inside the component.

0reactions
tiagodjfcommented, Aug 27, 2019

Thanks all!

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS Styling didn't get applied when class added dynamically ...
"currentDay" is the class I wanted and it is now added. Anyhow, I have a css for currentDay in g.html which says:
Read more >
Dynamic style - manipulating CSS with JavaScript - W3C Wiki
createElement function to create a new style element. This is useful when you want to give site visitors the option of changing your...
Read more >
Make Your CSS Dynamic with CSS Custom Properties - Toptal
Explore CSS custom properties and find out how they can be used to make better, more dynamic stylesheets.
Read more >
Dynamically add CSS class with JavaScript - Includehelp.com
In this post, we will learn how to dynamically add CSS class with JavaScript code. It is useful to add interactive dynamic functionality?...
Read more >
How to Dynamically Add/Remove Table Rows using jQuery
There are two issues. Firstly, as each row is being added dynamically, we cannot detect the click of a remove button directly by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found