+ 1

CSS not rendering appended HTML elements in Playground

In a program (run with browser, not Playground) that injects HTML elements, the defined class of the element (defined in the js file) will usually be recognized by the CSS file and rendered by it. However, in Playground, this doesn’t happen, and the element is left untouched by the CSS file. Are there any workarounds for this problem? Or do I have to define the CSS style in the style attribute of the element? Thanks.

29th Jun 2018, 3:26 PM
privrax.
privrax. - avatar
6 odpowiedzi
+ 2
The problem is actually the .class property. The right way to add the class is .className. text.className = "text-element";
29th Jun 2018, 5:58 PM
Boris Batinkov
Boris Batinkov - avatar
+ 3
It does happen In playground too. Please show your code.
29th Jun 2018, 4:34 PM
Calviղ
Calviղ - avatar
+ 1
https://code.sololearn.com/Wb2VlHgq9DA6/?ref=app read the css. the text should be red. whats happening is the SL server is running the HTML, then the CSS, then the JS. The CSS doesnt recognize it because it isnt running constantly
29th Jun 2018, 4:43 PM
privrax.
privrax. - avatar
+ 1
Thanks, it worked.
29th Jun 2018, 6:17 PM
privrax.
privrax. - avatar
0
You can try that way in JS: text.style.color = "red";
29th Jun 2018, 5:27 PM
Boris Batinkov
Boris Batinkov - avatar
0
Thats what I’m tryin to avoid, but thanks for you answer Boris Batinkov.
29th Jun 2018, 5:29 PM
privrax.
privrax. - avatar