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
4 ответов
+ 1
Holger Edud Angulo Castillo hi,
The style should apply to an element I think.
+ 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" ;
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?
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.