simple solution using your example that works Create a js file "test.js" containing : $('#freediv').html('<h1 id="test">test</h1>'); $("#test").click(function(){ alert("Bla"); }); I used an <a> tag in html to click to call the test.js file as follows: <script type="text/_javascript_"> $(document).ready(function() { $('a').click(function(){ $.getScript("test.js"); }); }); </script> </head> <body> <a href="">Click Here</a> <div id="freediv"></div> </body> </html> Snef wrote: The 'problem' using .live() is that i need to have all the scripts loaded even when they are not used. I just wanted to have only the scripts related to that form.The check is either in 'view generated source' in FF and the dom inspector. I'm not sure about eval, sounds like evil ;) A simple alert is executed, but can not be seen in the source (and i think that;s why jQuery code doesn;t work). Also tried it to use the $(document).ready, without success. Jake schreef:I'd suggest .live() still. Or maybe you could try eval() those _javascript_ code after Ajax fetch and DOM manipulation complete manually? btw, do you check the page source using `view page source' or firebug's dom inspector? latter recommended. On Apr 15, 3:56 pm, Snef <sne...@gmail.com> wrote: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 ;) |
- [jQuery] Handling html with javascript in .html() Snef
- [jQuery] Re: Handling html with javascript in .html... Jake
- [jQuery] Re: Handling html with javascript in .... Snef
- [jQuery] Re: Handling html with javascript ... Charlie Tomlinson
- [jQuery] Re: Handling html with javascript in .html... András Csányi
- [jQuery] Re: Handling html with javascript in .html... Donny Kurnia