Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > JavaScript errors trying to add event listeners for onclick() using DOM and AJAX

Thread Tools

JavaScript errors trying to add event listeners for onclick() using DOM and AJAX

Posts: n/a

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?

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
David Mark's Essential Javascript Tips - Volume #8 - Tip #47E -Attaching and Detaching Event Listeners David Mark Javascript 1 12-17-2011 08:07 AM
Find all event listeners on a link, including delegated listeners? Matt Kruse Javascript 2 05-28-2010 06:28 AM
JavaScript errors trying to add onclick listeners using DOM donpro Javascript 1 10-29-2007 08:49 PM
JavaScript error trying to add event listeners using DOM and AJAX donpro Javascript 0 10-29-2007 05:48 PM
detect javascript event listeners Javascript 0 07-26-2006 06:58 AM