0

Why don't it recognize the fontfamily property?

hello entrepreneurs. I am stranded in a code with javascript which consists of giving a variable a cursive font and then giving display with a document.write() https://code.sololearn.com/Wcl21Dj4rYgI/?ref=app

5th Jul 2020, 7:47 PM
Holger Edud Angulo Castillo
Holger Edud Angulo Castillo - avatar
4 odpowiedzi
+ 1
Holger Edud Angulo Castillo hi, The style should apply to an element I think.
5th Jul 2020, 10:38 PM
EmmanueLZ.
EmmanueLZ. - avatar
+ 1
this may help you i think style works on elements/nodes of html in script var elem = "<h2 id='demo'>this is a demo </h2>" ; document.write(elem); var demo = document.querySelector("#demo") ; demo.style.fontFamily = "cursive" ;
7th Jul 2020, 1:59 AM
Divya Mohan
Divya Mohan - avatar
0
Lo hice de esta forma: <style> .myclass{font-family:cursive;font-size:2em;} </style> </head> <body> <p id="demo"></p> </body> <script> let text="Hello world"; let x=document.getElementById("demo"); x.innerHTML=text; x.setAttribute("class","myclass"); </script> Pero yo quería hacer algo rápido y ahorrarme muchas líneas de código. ¿ Será que con jquery es posible?
5th Jul 2020, 11:25 PM
Holger Edud Angulo Castillo
Holger Edud Angulo Castillo - avatar
0
I don't know very well jQuery but in your code, instead of saludos.style.fontFamily, you can use document.body.style.fontFamily and it will work.
5th Jul 2020, 11:34 PM
EmmanueLZ.
EmmanueLZ. - avatar