Help me with this level.

Alphabetize

[deleted user]
10 years ago

0

Hi,
The console Google Chrome says :
Uncaught TypeError: Cannot read property ‘innerHTML’ of undefined

when I put :
var id = document.getElementsByName(“words”)[0].innerHTML;

I make a error?

Thanks

9replies
7voices
224views

0

Does this DOM element even exist?
document.getElementsByName("words")[0]

[deleted user]
10 years ago

0

A ! Ok . I have understand.
It’s my computer who are to slow for the timer :/

Thx

synstealth
10 years ago

0

its easy to think like this way : the html page is the document itself, then you select the id=“somename” or name=“somename” to select the element you want to focus on, then the [0] tells you which forms in case there is more than one of the same element you are looking for, then select it’s property association ( .value or .innerHTML)

docuement.getElementByID(“somename”) or getElementByName(“somename”) — you must remember that “somename” must exist in the form id or name attribute.

synstealth
10 years ago

0

form id, tag id or one of the tag attributes you want to focus on.

Zewo
9 years ago | edited 9 years ago

0

Read some about those functions, you’ll probably see one who could help you alot =)

Here’s a quick list of the functions you can use :

http://xahlee.info/js/js_get_elements.html

tl0tr
9 years ago

0

The tertarea doesn’t even have that name attribute. Also I don’t think you need to put the word var in the cosole. Just mention the name of the variable then = and then the code. Atleast in firefox I didn’t had to mention it. I think it would be the same in chrome too. I might be wrong though.

dloser
9 years ago

0

Medal-hunting session has already started? So early this year. :p

You never have to use ‘var’ in JavaScript. However, it is good practice to do so to avoid mistakes and polluting the global scope. In some cases, like recursive functions, not using it can cause a lot of confusion. :)

Zewo
9 years ago

0

I didn’t knew that i didn’t have to use the word var ! Could someone explain me ? =)

Reply has been removed
dloser
9 years ago | edited 9 years ago

0

It’s just part of the language that you don’t have to. If you don’t, the variable will be looked for in the available scopes (current block, current function, [s]calling function,[/s] etc.) and if it’s not found, it will be created in the global scope.

EDIT: Scope of calling function is not used, of course. I meant the function in which a function is defined.

You must be logged in to reply to this discussion. Login
1 of 10

This site only uses cookies that are essential for the functionality of this website. Cookies are not used for tracking or marketing purposes.

By using our site, you acknowledge that you have read and understand our Privacy Policy, and Terms of Service.

Dismiss