New course! Every coder should learn Generative AI!
Try a free lesson+ 1
Need a little help at JS.
In my this code... <style> #ChandlerBing { background-color:red; width:456px; height:456px; }</style> <script> var JoeyTribbiani=document.getElementById ("ChandlerBing"); JoeyTribbiani.style.height=1px;</script> Why my code is not working and how can I correct it? Thanks for answering.
9 Answers
+ 2
The only possible reason i can think of is that sololearn platform runs the JS first before the HTML is loaded, so it is detecting the style being null. So I suggest the following instead:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<div id="Bing">hjw</div>
</body>
<script>
var Bong=document.getElementById("Bing");
Bong.style.height="1px";
</script>
</html>
By putting the script at the bottom (instead of under JS tab), this ensures that the script is run after the HTML is loaded
+ 1
U can try this with quotation mark:
JoeyTribbiani.style.height = "1px";
It should work :)
+ 1
what error did u experience? The result shd be showing you 1px height instead of 456px right away
+ 1
Don't ask me why, but I changed the double quotations to single quotations and I think that I got it to work.
Jo.style.height='1px';
0
I have tried it, still an error
0
I have tried it, still an error
0
I have tried it, still an error
0
Still an error
https://code.sololearn.com/WHf4cRT3bg83/?ref=app