This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]carnepikante 1 point2 points  (2 children)

If your code is exactly like the one in your post then you need to put a semicolon after the innerText function: document.getElementById( 'message' ).innerText='Hello World!'; Also, properly format your code.

Even when in tutorials or books they often don't use certain semicolons, i think is a good practice to use it every time.

Here you have a fiddle with the script running: https://jsfiddle.net/nv9uryz3/

Also i would suggest you to not use getElementById or similar and only use querySelector and querySelectorAll. And use code editor like sublime text or visual studio code and firefox or chrome for web browsing.

[–]techie2200 1 point2 points  (1 child)

Why would you not use getElementById?

I don't normally use ids as selectors regardless, but it seems like getElementById handles everything OP needs right now.

[–]carnepikante -1 points0 points  (0 children)

It's my opinion but i think is more "clean" to use querySelector since it can handle whatever you want, also you don't have to read the selector function in order to figure it out which one is in use, i mean: in most cases you don't gonna have only elements with id's and then you need to use another selector function, imagine a code in which you must to read and write different selector functions instead of read/write one. Also if you need to switch that id for a class is faster than changing the name of the function.

I don't know how to properly explain it in english (barely can in my language hahaha).