+ 5
Java script error, DOM handling
Hello everyone, in this code I'm trying to make a side menu appear when you click on the image. But it’s not working, I ask your help to resolve . Thanks for listening https://code.sololearn.com/WT5uWfMN2CIH/?ref=app Error full code https://code.sololearn.com/W5abU8KDV2yK/?ref=app
17 Réponses
+ 2
https://code.sololearn.com/Wcdph5FJPPK0/?ref=app
+ 6
//Put the 50% in “quotes”:
m1.style.width = "50%";
+ 5
/*
Oh...
Does this work?
*/
var m1;
window.onload = function() {
m1 = document.getElementById("menu-1");
}
function openm1(){
m1.style.width = "50%";
}
+ 4
/*
It worked for me...
Here’s the full code which worked for me:
*/
var m1 = document.getElementById("menu-1");
function openm1(){
m1.style.width = "50%";
}
+ 4
strange, I copied and pasted your code and it's still not working.
+ 4
/*
Oh, you mean the margin from the top?
Add this into the CSS after `position: absolute;`:
*/
top: 0;
+ 4
I would assume that SoloLearn puts the JS at the end of the <head> tag, where the <body> and the rest of the document isn’t loaded yet. Putting window.onload makes sure that everything’s loaded before it starts.
+ 3
Rowsej Did not work :/
+ 3
Setting top to 0 makes sure that there are 0 pixels from the top of the screen to the top of the element.
Do you mean getting a copy of the final solved code? I can do that.
+ 2
the question of appearing the menu has been solved, but with that another problem arose, now there is a kind of "margin", how do I solve this? (thank you very much)
+ 2
oh man, this works perfectly, now i don't know if it's asking too much, can you explain to me how you solved it? because in the original code I would have to repeat this process many times
+ 2
I'm saying in relation to window.onload, I would like to know why what I did was wrong
+ 2
If you want to see the entire code, I edited the question and put it at the very endIf you want to see the entire code, I edited the question and put it at the very endIf you want to see the entire code, I edited the question and put it at the end
+ 2
Check this
+ 1
Wow, perfect ! thank you
+ 1
You have to enclose the 50% value in quotes like this
"50%"
0
but, only the last image is opening the menu