Hello! I''m new to Prototype JS programming but I encountered this error developing a Web 2.0 app on Firefox (on Safari everything is all right; on IE, damn, I don''t know =) ) var img = new Object(); img.element = toSel.getElementsByTagName("img")[0]; img.src = img.element.readAttribute("src"); img.alt = img.element.readAttribute("alt"); img.name = img.src.replace(".png", ""); img.element.replace(''<img src="'' + img.name + ''_sel.png" alt="'' + img.alt + ''" />''); ...and Firefox gives me a "No attribute error for img.src"... So I walked around the problem substituting directly innerHTML...but it should be great to understand the problem...I hope somebody could me help! Thanks in advance, Marco --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Aug 11, 5:41 am, muccy <muccy...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello! > I''m new to Prototype JS programming but I encountered this error > developing a Web 2.0 app on Firefox (on Safari everything is all > right; on IE, damn, I don''t know =) )I guess you are trying to copy the attributes of one element to another. Consider using cloneNode.> var img = new Object(); > img.element = toSel.getElementsByTagName("img")[0];Presumably toSel is a reference to an HTML element that has some img elements as descendants.> img.src = img.element.readAttribute("src"); > img.alt = img.element.readAttribute("alt"); > img.name = img.src.replace(".png", ""); > img.element.replace(''<img src="'' + img.name + ''_sel.png" alt="'' + > img.alt + ''" />'');I don''t see the point in copying attributes to an object just so you can then use them in innerHTML. Consider: var srcImg = toSel.getElementsByTagName("img")[0]; var newImg = document.createElement(''img''); newImg.src = srcImg.src.replace(''.png'', ''''); srcImg.parentNode.replaceChild(newImg, srcImg); Or just change the src attribute of the original image. var img = toSel.getElementsByTagName("img")[0]; img.src = img.src.replace(''.png'', ''_sel.png''); -- Rob --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Aug 11, 2:00 pm, RobG <rg...-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote:> On Aug 11, 5:41 am,muccy<muccy...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hello! > > I''m new to Prototype JS programming but I encountered this error > > developing a Web 2.0 app on Firefox (on Safari everything is all > > right; on IE, damn, I don''t know =) ) > > I guess you are trying to copy the attributes of one element to > another. Consider using cloneNode. > > > var img = new Object(); > > img.element = toSel.getElementsByTagName("img")[0]; > > Presumably toSel is a reference to an HTML element that has some img > elements as descendants. > > > img.src = img.element.readAttribute("src"); > > img.alt = img.element.readAttribute("alt"); > > img.name = img.src.replace(".png", ""); > > img.element.replace(''<img src="'' + img.name + ''_sel.png" alt="'' + > > img.alt + ''" />''); > > I don''t see the point in copying attributes to an object just so you > can then use them in innerHTML. Consider: > > var srcImg = toSel.getElementsByTagName("img")[0]; > var newImg = document.createElement(''img''); > newImg.src = srcImg.src.replace(''.png'', ''''); > srcImg.parentNode.replaceChild(newImg, srcImg); > > Or just change the src attribute of the original image. >It''s what I''ve done...I''m very new to JS+Prototype...I''m just discovering this "World" =)> var img = toSel.getElementsByTagName("img")[0]; > img.src = img.src.replace(''.png'', ''_sel.png''); > > -- > RobThank you very much =) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Aug 14, 8:54 am, muccy <muccy...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Aug 11, 2:00 pm, RobG <rg...-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote:[...]> > Or just change the src attribute of the original image. > > It''s what I''ve done...I''m very new to JS+Prototype...I''m just > discovering this "World" =)It is best to learn javascript and the W3C DOM (at least the basics) before attempting to use a library. As you go, try to always ensure you know whether a paricular function or property belongs to the ECMAScript language, the host environment (the DOM) or the library. If you only learn to program using the library with a version of "guess-and-go", you will have never be able to write javascript for environments that the library doesn''t support or write efficient code. -- Rob --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You''re right. In fact I''ve started with pure JS + DOM. Then I rewrote some parts of my project using Prototype. On Aug 14, 1:57 am, RobG <rg...-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote:> On Aug 14, 8:54 am,muccy<muccy...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > On Aug 11, 2:00 pm, RobG <rg...-AFFH1GffN5hPR4JQBCEnsQ@public.gmane.org> wrote: > [...] > > > Or just change the src attribute of the original image. > > > It''s what I''ve done...I''m very new to JS+Prototype...I''m just > > discovering this "World" =) > > It is best to learn javascript and the W3C DOM (at least the basics) > before attempting to use a library. As you go, try to always ensure > you know whether a paricular function or property belongs to the > ECMAScript language, the host environment (the DOM) or the library. > > If you only learn to program using the library with a version of > "guess-and-go", you will have never be able to write javascript for > environments that the library doesn''t support or write efficient code. > > -- > Rob--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---