JavaScript errors trying to add onclick listeners using DOM

D

donpro

I've managed to separate JavaScript from my code by employing DOM
listeners and coding in separate JS files in all of my modules except
one.

I have a PHP file called via an AJAX routine which returns a table.
In the <th> tags representing my columns headers, I've had to add the
JavaScript onclick() code to the <a> tags as attempting to add DOM
Listeners fails with "obj has no properties" - I suspect it probably
has to do with the nature of the AJAX call and the fact that this code
doesn't exist in the calling file and so not part of the original DOM
tree.

So I guess I have no choice but to leave the JavaScript onclick() code
in their - maybe I'm overthinking this in that not everything must be
separated?

Or is there a way...

Thanks,
Don
 
T

Thomas 'PointedEars' Lahn

donpro said:
I've managed to separate JavaScript from my code by employing DOM
listeners and coding in separate JS files in all of my modules except
one.

I have a PHP file called via an AJAX routine which returns a table.
In the <th> tags representing my columns headers, I've had to add the
JavaScript onclick() code to the <a> tags as attempting to add DOM
Listeners fails with "obj has no properties" - I suspect it probably
has to do with the nature of the AJAX call and the fact that this code
doesn't exist in the calling file and so not part of the original DOM
tree.

I guess it has to do with your accessing something that is not an object
instead.
So I guess I have no choice but to leave the JavaScript onclick() code
in their - maybe I'm overthinking this in that not everything must be
separated?

Yes, definitely. It usually doesn't make sense to separate a DOM script
and the document it is operating on. Probably someone has told you that
already, but you would not have listened.
Or is there a way...

There is a way to do this realiably, interoperable and efficiently,
but it can not be found down the road you are going.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top