JavaScript error trying to add event listeners using DOM and AJAX

D

donpro

Hi,

I have PHP file called file1.php with an empty <div></div> in the
middle. I've added a 'load' event listener so that on page load, it
calls an AJAX function that calls file2.php. file2.php creates a
table and loads it into the <div></div> in file1.php.

file2.php has <a> tags in it's <th> columns and I wish to trap when a
user clicks on the column heading. The old way was to use the
onclick() method but I'd rather use event listeners.

Here's my problem. I am getting "obj has no properties" when trying
to add those listeners. I *think* it is because the code in file2.php
isn't part of the original DOM tree for file1.php. So how can I use
event listeners instead of onlclick()? I know I can add top the DOM
by creating elements and appending them but that adds to the HTML code
and my code is already in place via the AJAX call.

What to do...? DO I just use the old passe onclick() method?
 

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

Forum statistics

Threads
473,996
Messages
2,570,237
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top