Currently, I have the following code: <html> <head> ... </head> <body> <div> <script type="text/javascript"> <!-- document.write(''<span>Test</span>''); //--> </script> </div> </body> </html> How to replace the JavaScript in Prototype''s style: new Element? I need something similar: <div> <script type="text/javascript"> <!-- var span = new Element(''span''); document.write(span); // <- THAT IS </script> </div> I mean, I need to place <new Element> in DOM there script is called ;-) How to do it? Exactly threre the script is called, ''cause I don''t known where it called ;-) Thank you ;-) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Polgardy
2008-Jun-13 13:40 UTC
Re: How to do <document.write> in Prototype style?
See my response to your other question. :-) There are legitimate uses for document.write though. Document.write() will write the output into the HTML source immediately (good for loading dependent libraries or stylesheets), but element injection requires the DOM to be already built. -Fred On Fri, Jun 13, 2008 at 8:02 AM, AlannY <m@alanny.ru> wrote:> How to replace the JavaScript in Prototype''s style: new Element? > > I need something similar: > > <div> > <script type="text/javascript"> > <!-- > var span = new Element(''span''); > document.write(span); // <- THAT IS > </script> > </div> > > I mean, I need to place <new Element> in DOM there script is > called ;-) How to do it? Exactly threre the script is called, ''cause I > don''t known where it called ;-) > > Thank you ;-)-- Science answers questions; philosophy questions answers. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
It''s not helps ;-( Because, I really don''t known where to place my new elements ;-( So, If using <new Element> style, I need to specify an ID of some div, for example: <div id="somediv"> <script> <!-- var span = new Element(''span''); $(''somediv'').appendChild(span); //--> </script> </div> But, I don''t want to specify an ID, I want just to <write> elements ;- ( As I can see - it''s impossible! Am I right? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
<html> <head> <script type="text/javascript"> function init() { mySpan = new Element(''span''); $(''importantButton'').observe(''click'', updateMyContent); } function updateMyContent() { mySpan.update(''Some important text''); $(''canvas'').appendChild(mySpan); } document.observe(''dom:loaded'', init); </script> </head> <body> <div id="canvas"></div> <button id="importantButton">Press me to see some important text</ button> </body> </html> On Jun 13, 9:02 am, AlannY <m...-I/IS3f7Pe4GHXe+LvDLADg@public.gmane.org> wrote:> Currently, I have the following code: > > <html> > <head> > ... > </head> > <body> > > <div> > <script type="text/javascript"> > <!-- > document.write(''<span>Test</span>''); > //--> > </script> > </div> > > </body> > </html> > > How to replace the JavaScript in Prototype''s style: new Element? > > I need something similar: > > <div> > <script type="text/javascript"> > <!-- > var span = new Element(''span''); > document.write(span); // <- THAT IS > </script> > </div> > > I mean, I need to place <new Element> in DOM there script is > called ;-) How to do it? Exactly threre the script is called, ''cause I > don''t known where it called ;-) > > Thank you ;-)--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I would auggest that you take a different pespective on how you are developing your pages. You should be able to reference any element within your page. That means specifying an ID, or creating an element dynamically. You should strive to keep Javascript separate from your HTML. Bernie On Jun 13, 10:26 am, AlannY <m...-I/IS3f7Pe4GHXe+LvDLADg@public.gmane.org> wrote:> It''s not helps ;-( Because, I really don''t known where to place my new > elements ;-( > > So, If using <new Element> style, I need to specify an ID of some div, > for example: > > <div id="somediv"> > <script> > <!-- > var span = new Element(''span''); > $(''somediv'').appendChild(span); > //--> > </script> > </div> > > But, I don''t want to specify an ID, I want just to <write> elements ;- > ( > > As I can see - it''s impossible! Am I right?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Polgardy
2008-Jun-13 14:41 UTC
Re: How to do <document.write> in Prototype style?
There is support for this in different browsers, but it''s not standard. In Firefox, you could say: Builder.dump(); function outputElement(e) { return new XMLSerializer().serializeToString(e); } document.write(outputElement(TABLE({id: ''mytable''}, [ TR([ TD(''cell 1''), TD(''cell 2''), TD(''cell 3'') ]) ]))); Still have to use document.write(), but you could build up the element programmatically. I agree with @blechler though, this really isn''t the recommended approach for doing dynamic HTML development. -Fred On Fri, Jun 13, 2008 at 9:26 AM, AlannY <m@alanny.ru> wrote:> > > But, I don''t want to specify an ID, I want just to <write> elements ;- > ( > > As I can see - it''s impossible! Am I right?-- Science answers questions; philosophy questions answers. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
OK, Alright ;-) I understand you all ;-) Thank a lot ;-) I have found already a better way with HTML abstraction ;-) Thank you all ;-) On Jun 13, 6:38 pm, blechler <lech...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I would auggest that you take a different pespective on how you are > developing your pages. You should be able to reference any element > within your page. That means specifying an ID, or creating an element > dynamically. You should strive to keep Javascript separate from your > HTML. > > Bernie > > On Jun 13, 10:26 am, AlannY <m...-I/IS3f7Pe4GHXe+LvDLADg@public.gmane.org> wrote: > > > It''s not helps ;-( Because, I really don''t known where to place my new > > elements ;-( > > > So, If using <new Element> style, I need to specify an ID of some div, > > for example: > > > <div id="somediv"> > > <script> > > <!-- > > var span = new Element(''span''); > > $(''somediv'').appendChild(span); > > //--> > > </script> > > </div> > > > But, I don''t want to specify an ID, I want just to <write> elements ;- > > ( > > > As I can see - it''s impossible! Am I right?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---