+ 2

Embedding CSS in JavaScript

1. Is it possible to embed CSS in JavaScript? 2. If possible, What are its limitations, Pro’s and Con’s? 3. Is it good practice? If not why is it not good practice? Wish you reply and show me example for these questions It’s ok if you don’t know answer to all but if you know answer to anyone and u reply, it would be really considered a huge help! Thank You đŸ™ŒđŸ»đŸ€

5th Apr 2018, 8:13 AM
Raaja Thalapathy
Raaja Thalapathy - avatar
4 Answers
+ 4
well embedding css in js doesn't make too much sense,you cannot directly embed css in js,and when it is done it slows done your code.an example: style=document.createElement("style"); document.append(style); style.innerHTML=" body{ color:blue; text- align:center; } ";
5th Apr 2018, 8:31 AM
᠌᠌Code X
᠌᠌Code X - avatar
+ 1
Like 🇳🇬Brains answer, yes its possible but is not good practice because make code more fragmented... In html you insert content, css for style and js for interactions but if you insert in js some css/html code or in html some css/js code you make code more caothics... You can do it only if necessary (in your case in necessary only in web page script injection) else dont mix they
5th Apr 2018, 9:02 AM
KrOW
KrOW - avatar
+ 1
Oh ok I get it thanks @Brains đŸ˜đŸ™ŒđŸ»
5th Apr 2018, 9:34 AM
Raaja Thalapathy
Raaja Thalapathy - avatar
+ 1
Ya sure I’ll do it only if necessary @KrOW Thanks man, Cheers đŸ„‚đŸ˜‰
5th Apr 2018, 9:35 AM
Raaja Thalapathy
Raaja Thalapathy - avatar