2009/4/15 Snef <sne...@gmail.com>: > > When using $.ajax() i encounter some problems. > > With the ajax I'm calling a script that will return some html. When > echoing the returned data, I can see that everything is returned > including the javascript tags. > > When 'inserting' the returned data into a div on the screen, the > javascript seems to be executed but i can't see it in the generated > source! > > I cut it all down to some simple insertion of html into a div like > this: > > $("#freediv").html('<h1 id="test">test</h1><script > language="javascript" type="text/javascript">alert("Bla");</ > script><p>Bla bla</p>'); > > The html is inserted in #freediv but i can't see the script tags > (although alert("Bla") did get executed). > > The real problem is when i try to use some jQuery in the html: > > $("#freediv").html('<h1 id="test">test</h1><script > language="javascript" type="text/javascript">$("#test").click(function > (){ alert("Bla"});</script><p>Bla bla</p>'); > > Isn't this possible at all? > > I'm using this to create some 'popup' forms (maybe with SimpleModal) > and I want to include some javascript into the response that is > specific for that form (like validation and other actions). I know i > can use liveQuery or even jQuery's live() but then i need to have all > the javascript for every used form already in the main document. > > I hope you understand my problem ;)
I understand because my application works fine and use this way (I hope this is the right expression at this case :$) So, in my application the html code with jquery source looks like this (I refactored your code upper): $("#freediv").html('<h1 id="test">test</h1><script language="javascript" type="text/javascript"> --> this line! $(document).ready(function() { $("#test").click(function (){ alert("Bla"}); --> this line! }) </script><p>Bla bla</p>'); Note that I'm using every case the $(document).ready(function(){--my code--}) part. Not so beaty but works! :D I suggest you try it this way. András -- - - -- Csanyi Andras -- http://sayusi.hu -- Sayusi Ando -- "Bízzál Istenben és tartsd szárazon a puskaport!".-- Cromwell