+ 6

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

18th Aug 2020, 5:51 AM
João Hoffman
João Hoffman - avatar
17 Réponses
+ 3
https://code.sololearn.com/Wcdph5FJPPK0/?ref=app
18th Aug 2020, 3:13 PM
Divyansh Srivastava
Divyansh Srivastava - avatar
+ 7
//Put the 50% in “quotes”: m1.style.width = "50%";
18th Aug 2020, 5:53 AM
Rowsej
Rowsej - avatar
+ 5
/* Oh... Does this work? */ var m1; window.onload = function() { m1 = document.getElementById("menu-1"); } function openm1(){ m1.style.width = "50%"; }
18th Aug 2020, 6:06 AM
Rowsej
Rowsej - avatar
+ 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%"; }
18th Aug 2020, 5:57 AM
Rowsej
Rowsej - avatar
+ 4
strange, I copied and pasted your code and it's still not working.
18th Aug 2020, 5:58 AM
João Hoffman
João Hoffman - avatar
+ 4
/* Oh, you mean the margin from the top? Add this into the CSS after `position: absolute;`: */ top: 0;
18th Aug 2020, 6:17 AM
Rowsej
Rowsej - avatar
+ 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.
18th Aug 2020, 6:34 AM
Rowsej
Rowsej - avatar
+ 3
Rowsej Did not work :/
18th Aug 2020, 5:55 AM
João Hoffman
João Hoffman - avatar
+ 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.
18th Aug 2020, 6:29 AM
Rowsej
Rowsej - avatar
+ 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)
18th Aug 2020, 6:09 AM
João Hoffman
João Hoffman - avatar
+ 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
18th Aug 2020, 6:27 AM
João Hoffman
João Hoffman - avatar
+ 2
I'm saying in relation to window.onload, I would like to know why what I did was wrong
18th Aug 2020, 6:31 AM
João Hoffman
João Hoffman - avatar
+ 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
18th Aug 2020, 6:34 AM
João Hoffman
João Hoffman - avatar
+ 2
Check this
18th Aug 2020, 3:13 PM
Divyansh Srivastava
Divyansh Srivastava - avatar
+ 1
Wow, perfect ! thank you
18th Aug 2020, 4:22 PM
João Hoffman
João Hoffman - avatar
+ 1
You have to enclose the 50% value in quotes like this "50%"
19th Aug 2020, 3:31 PM
Steve Sajeev
Steve Sajeev - avatar
0
but, only the last image is opening the menu
18th Aug 2020, 4:23 PM
João Hoffman
João Hoffman - avatar