r/JavaScriptTips • u/Khabibulix • Feb 08 '21
Problem with click element, syntax error maybe? Sorry 4 bad quality...
3
u/DownRyte Feb 08 '21
If this is a HTML (which it looks like it is) then you can’t have the code that is on and after line 27 there. You need to either put that code in between script tags before the end of the body or put It in a file named “script.js” and make 8 self closing. Feel free to PM me if that didn’t make sense.
1
u/Khabibulix Feb 09 '21
Hello and thanks for your fast answer, in fact it is in a script.js but I copy paste in the HTML file to make it more...readable 😏
1
u/TeslaRanger Feb 09 '21
The <h1> stuff in the <head> section belongs down in the <body> section too, and pay attention to indenting and more importantly to your syntax coloring starting with the closing script tag.
2
u/Khabibulix Feb 09 '21
Ahoy, TeslaRanger! Hope you'll have a nice day, I moved the h1 as u said and indented like a pro. I think the baaad color comes from the fact that I copy paste html in my script.js making it clumsy... Thanks again, my code is prettier now!
4
u/classy_variable Feb 09 '21 edited Feb 09 '21
When you’re selecting an element by id using getElementById you shouldn’t use the # identifier there. You already specify the argument is an id because of the method name. It should be document.getElementById(“sub”)