tags:

views:

97

answers:

2

Hi, I m working in Jquery..Since i m new to JQuery .i m having a doubt tat i have created a DIV inside that DIv i have one label and a Textbox..What i m trying to do is on clicking on that Generated Div , i need to show some existing value... But when i m clicking my DIv i kept an alert to check is that click event working.But that click not working... So, please suggest would the new created Divs are not allowed to Event clicking????? My code is,

     $("<div id=field></div>").appendTo("#displayPanel");
   $("<label id=labelstr>untitled1</label>").appendTo("#displayPanel #field");
   $("<input id=inputstr type= 'text' ></input>").appendTo("#displayPanel #field");

 $("#displayPanel #field").click(function (){alert("div clicked");});
+2  A: 

There's nothing that would prevent a new div element from being clicked. And in fact, I would suggest that something else on the page is preventing it from working (maybe a duplicate ID?)

Your code works just fine in isolation.

altCognito
yA I M GETTING NOW.actually i m creating the div inside some function and i kept the .click line outside that function ..Now i put both these inside the function and i m getting the result now.Thank U>.
Aruna
+1  A: 

You want the jQuery live function

It allows you to add events to elements that are loaded after the DOM finishes loading.

Mark Hurd
Thanks! ... found at exactly correct time. I do like this SO thing ...
brad