That's because the element did not exist when you assigned the click
handler. Have a look at the liveQuery plugin [1] or otherwise make
sure that any newly-created elements are given notice of how the're
supposed to act when you introduce them to the document.

[1] http://brandonaaron.net/docs/livequery/

On Thu, Dec 4, 2008 at 11:06 AM, fabrice.regnier
<[EMAIL PROTECTED]> wrote:
>
> hi to all ;)
>
> It seems that click function doesn't work on html element created on
> the fly with jquery. Where am i wrong ?
>
> When i click on the checkbox from paragraph "P2", i got the alert.
> But when i click on the checkbox from paragraph "P1" created on the
> fly (when i submit a button), then i got no alert.
>
> regards,
>
> f.
>
> Here is my code:
>
> JQUERY Part:
>
> $("#Idsubmit").click(function () {
>        $("#P1").html('<input type="checkbox" value="soft_boo">soft_boo');
> });
>
> $(":checkbox").click(function () {
>        alert("foo");
> });
>
>
> HTML Part:
> <input id="Idsubmit" type="button" value="afficher">
> <p id="P1"></p>
> <p id="P2"><input type="checkbox" value="hard_boo">hard_boo</p>
>

Reply via email to