There are a lot of ways to do this, here are a couple:

$("#div99").append("<a id='alnDiv99' href='#'>I am in div99</a>").click
(function(){alert("hello world");});

$("<a/>").attr({id:"alnDiv99", href:"#"}).text("I am in div99").click
(function(){alert("hello world");}).appendTo("#div99");


On Aug 20, 6:42 am, Audrey A Lee <audrey.lee.is...@gmail.com> wrote:
> 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 via email to