jQuery: click-event-handler for dynamically created a-elements?

0 views
Skip to first unread message

Audrey A Lee

unread,
Aug 20, 2009, 6:46:07 AM8/20/09
to forumgrouper
Hello,

I've been working with jQuery about 20 hours now.

I like it.

I am looking for a demo of putting an a-element inside a div-element.

This seems to work:

$("#div99")[0].innerHTML = "<a id='aInDiv99' href='#'>I am in div99</
a>";

I'd like to handle its click-event.

I wrote this:

$("a#aInDiv99").click(function(event){alert("hello world");});

The click event does not fire when I click 'aInDiv99'

Is there a recipe for writing a click-event-handler for dynamically
created a-elements?

Oh, here is my world:
- jquery-1.3.2.js
- Safari 4.0.3
- Firefox 3.5.2

-Audrey
Reply all
Reply to author
Forward
0 new messages