Embedding CSS in JavaScript | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
+ 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
į Œį ŒBrains[Abidemi]
į Œį ŒBrains[Abidemi] - 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