Problem with my code, check description. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Problem with my code, check description.

In js: function change(){ var x = document.getElementById('het'); if (x.style.display === 'none') { p.style.display = 'none'; x.style.display = 'block; }else{ p.style.display = 'block'; x.style.display = 'none; } } I'm using this to toggle the display of a paragraph but how do I code the x.style.___ part for font family since its two words ?

11th Apr 2017, 3:19 PM
Cole Reizenberg
Cole Reizenberg - avatar
4 Answers
+ 3
Try x.style['font-family'] = 'something' It's another way to access properties of any object.
11th Apr 2017, 3:22 PM
Ashwani Kumar
Ashwani Kumar - avatar
+ 2
use camelCase. when there are two words or more, write them together, with them uppercased starting from the second one. like "backgroundColor" "fontFamily". so your code would be for exemple: x.style.fontFamily = 'Arial';
11th Apr 2017, 3:21 PM
Welliton Malta
Welliton Malta - avatar
+ 1
p.style.fontFamily = 'Arial';
11th Apr 2017, 3:26 PM
Calviղ
Calviղ - avatar
0
Thanks guys!
11th Apr 2017, 3:45 PM
Cole Reizenberg
Cole Reizenberg - avatar