doesn't do what you think it does. This will actually run title_link_clicked() immediately and assign l.onclick its return value. Since the function only returns false, your l element won't get an onclick handler. And the function is also called before the i element is created, that's the reason for the undefined error.

What you want to do is:

l.onclick = title_link_clicked;

system
—
2013-08-21T10:08:49Z —
#3

You can also add this to your code:

l.addEventListener('click', title_link_clicked, false);

As said above, l.onclick means property access (l is the object, onclick is a property that happens to be a method also).

l.onclick = title_link_clicked();

means the function on the right side is executed, a function call.

l.onclick = title_link_clicked;

means the function on the right side is referenced, which is what you need.