I have a bit of code which displays subcomments nicely and a bit of js to hide them: <div> <input type="button", value="Subcomments", onclick="changeClass(''subcomNormal'')"> <div id = "subcomNormal" > <% comment.subcomments.each do |subcomment| %> <div id="subremark" > <p><%= subcomment.body %></p> <div id="commenter" > <p><%= subcomment.created_at %><%= subcomment.user_id %></p> </div> </div> <% end %> </div> </div> This is the js <script language="javascript" type="text/javascript"> function changeClass(subcomNormal) { if(document.getElementById(subcomNormal).className ==''subcomHide'') {document.getElementById(subcomNormal).className ''subcomNormal''; } else { document.getElementById(subcomNormal).className ''subcomHide''; } } </script> The subcomments on the first comments subcomments hide nicely but the subcomments button on the second and subsequent comments only bring back the subcomments on the first comment and has no effect on it''s own subcomments. Can anybody see where I am going wrong? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
>"The subcomments on the first comments subcomments" >.... >"the subcomments on the first comment and has no effect on it''s own >subcomments" >lol :) In jquery there is nice method toggle. .toggle( showOrHide ) showOrHideA Boolean indicating whether to show or hide the elements. With no parameters, the .toggle() method simply toggles the visibility of elements: $(''.target'').toggle(); http://api.jquery.com/toggle/ use it, it will simplify you code and maybe you''ll find out solution on your own. ---- http://blog.eugen.co -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On May 10, 1:30 pm, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I have a bit of code which displays subcomments nicely and a bit of js > to hide them: > > <div> > <input type="button", value="Subcomments", > onclick="changeClass(''subcomNormal'')"> > <div id = "subcomNormal" > > <% comment.subcomments.each do |subcomment| %> > <div id="subremark" > > <p><%= subcomment.body %></p> > <div id="commenter" > > <p><%= subcomment.created_at %><%= subcomment.user_id %></p> > </div> > </div> > <% end %> > </div> > </div> >Is this repeated for each comment? have multiple things on the page with the same id is a no-no: ids should be unique Fred> This is the js > > <script language="javascript" type="text/javascript"> > function changeClass(subcomNormal) { > if(document.getElementById(subcomNormal).className > ==''subcomHide'') > {document.getElementById(subcomNormal).className > ''subcomNormal''; } > else > { document.getElementById(subcomNormal).className > ''subcomHide''; } } > </script> > > The subcomments on the first comments subcomments hide nicely but the > subcomments button on the second and subsequent comments only bring back > the subcomments on the first comment and has no effect on it''s own > subcomments. > > Can anybody see where I am going wrong? > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Eugen Ciur wrote in post #997765:> > http://api.jquery.com/toggle/ > > use it, it will simplify you code and maybe you''ll find out solution on > your own.Never used jquery before, I see it''s simplicity compared to straight js I now have <% @user.comments.each do |comment| %> <div id="remark" ><p><%= comment.body %></p> <div id="commenter"><p><%= comment.story_id %> <%= comment.id %> </div> </div> <button>Hide</button> <div id = "subcomNormal" > <% comment.subcomments.each do |subcomment| %> <div id="subremark" > <p><%= subcomment.body %></p> <div id="commenter" > <p><%= subcomment.created_at %><%= subcomment.user_id %></p> </div> </div> <% end %> </div> <% end %> with <script> $("button").click(function () { $("#subcomNormal").toggle(); }); </script> It still gives the same problem i.e all Hide buttons affect the first comments subcomments -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote in post #997768:> Is this repeated for each comment? have multiple things on the page > with the same id is a no-no: ids should be unique > > FredThis is the full code <% @user.comments.each do |comment| %> <div id="remark" ><p><%= comment.body %></p> <div id="commenter"><p><%= comment.story_id %> <%= comment.id %> </div> </div> <button>Hide</button> <div id = "subcomNormal" > <% comment.subcomments.each do |subcomment| %> <div id="subremark" > <p><%= subcomment.body %></p> <div id="commenter" > <p><%= subcomment.created_at %><%= subcomment.user_id %></p> </div> </div> <% end %> </div> <% end %> Yes it is repeated for all comments. Both comments and subcomments have individual id''s I don''t see you point. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 10 May 2011, at 17:56, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Frederick Cheung wrote in post #997768: > >> Is this repeated for each comment? have multiple things on the page >> with the same id is a no-no: ids should be unique >> >> Fred > > > This is the full code > > <% @user.comments.each do |comment| %> > <div id="remark" ><p><%= comment.body %></p> > <div id="commenter"><p><%= comment.story_id %> <%= comment.id %> > </div> > </div> > <button>Hide</button> > <div id = "subcomNormal" > > <% comment.subcomments.each do |subcomment| %> > <div id="subremark" > > <p><%= subcomment.body %></p> > <div id="commenter" > > <p><%= subcomment.created_at %><%= subcomment.user_id %></p> > </div> > </div> > <% end %> > </div> > <% end %> > > Yes it is repeated for all comments. Both comments and subcomments have > individual id''s I don''t see you point. >Well for example you have multiple divs with id subcomNormal, and your onclick does getElementById(''subcomNormal''), which can''t know that you want (for example) the third item on the page with that id Fred> -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 10 May 2011 17:56, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Frederick Cheung wrote in post #997768: > >> Is this repeated for each comment? have multiple things on the page >> with the same id is a no-no: ids should be unique >> >> Fred > > > This is the full code > > <% @user.comments.each do |comment| %> > <div id="remark" ><p><%= comment.body %></p> > <div id="commenter"><p><%= comment.story_id %> <%= comment.id %> > </div> > </div> > <button>Hide</button> > <div id = "subcomNormal" > > <% comment.subcomments.each do |subcomment| %> > <div id="subremark" > > <p><%= subcomment.body %></p> > <div id="commenter" > > <p><%= subcomment.created_at %><%= subcomment.user_id %></p> > </div> > </div> > <% end %> > </div> > <% end %> > > Yes it is repeated for all comments. Both comments and subcomments have > individual id''s I don''t see you point.To check whether your html is valid, view the page in the browser and view the html using View >> Page Source (or similar). Then copy the complete text and paste it into the w3c html validator. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Quoting Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>:> On 10 May 2011 17:56, Neil Bye <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > > Frederick Cheung wrote in post #997768: > > > >> Is this repeated for each comment? have multiple things on the page > >> with the same id is a no-no: ids should be unique > >> > >> Fred > > > > > > This is the full code > > > > <% @user.comments.each do |comment| %> > > <div id="remark" ><p><%= comment.body %></p> > > <div id="commenter"><p><%= comment.story_id %> <%= comment.id %> > > </div> > > </div> > > <button>Hide</button> > > <div id = "subcomNormal" > > > <% comment.subcomments.each do |subcomment| %> > > <div id="subremark" > > > <p><%= subcomment.body %></p> > > <div id="commenter" > > > <p><%= subcomment.created_at %><%= subcomment.user_id %></p> > > </div> > > </div> > > <% end %> > > </div> > > <% end %> > > > > Yes it is repeated for all comments. Both comments and subcomments have > > individual id''s I don''t see you point. >They don''t have different ids. Every remark has the ID, ''remark''. Maybe you intended something like: <div id="<%= dom_id(comment) %>"> or simply: <div id="<%= "remark_#{comment[:id]}" %>"> HTH, Jeffrey -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Jeffrey L. Taylor wrote in post #997862: <div id="<%= "remark_#{comment[:id]}" %>">> > HTH, > JeffreyThanks that did the trick but I applied it to <div id="subcomNormal"> Neil -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Neil Bye wrote in post #998024:> Jeffrey L. Taylor wrote in post #997862: > <div id="<%= "remark_#{comment[:id]}" %>">I rebuilt the app in Rail 3 and the above no longer works. Has anybody an idea why? Or What can I use instead? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Aug 2, 12:22 pm, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Neil Bye wrote in post #998024: > > > Jeffrey L. Taylor wrote in post #997862: > > <div id="<%= "remark_#{comment[:id]}" %>"> > > I rebuilt the app in Rail 3 and the above no longer works. Has anybody > an idea why? Or What can I use instead? >How has the output changed? Fred> -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote in post #1014673:> On Aug 2, 12:22pm, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Neil Bye wrote in post #998024: >> >> > Jeffrey L. Taylor wrote in post #997862: >> > <div id="<%= "remark_#{comment[:id]}" %>"> >> >> I rebuilt the app in Rail 3 and the above no longer works. Has anybody >> an idea why? Or What can I use instead? >> > > How has the output changed? > > FredSimply rejects _#{comment[:id]} No output i.e no toggling atall not even on the first comment. I''ve attached _subcomment.html.erb Neil Attachments: http://www.ruby-forum.com/attachment/6494/_subcomment.html.erb -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Sorry the attachment is now correct, Id missed out the _#{comment[:id]} Neil Attachments: http://www.ruby-forum.com/attachment/6495/_subcomment.html.erb -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Aug 3, 11:30 am, Neil Bye <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Sorry the attachment is now correct, Id missed out the _#{comment[:id]} >it''s not in a <%= tag anymore Fred> Neil > > Attachments:http://www.ruby-forum.com/attachment/6495/_subcomment.html.erb > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Sorry still stuck. If you look at the attached _subcomment.html.erb you will see that I have put the jQuery inside the each loop and it obviously causes problems because the jQuery is repeated. It''s inside because I get an error on the comment variable otherwise. Any ideas Neil Attachments: http://www.ruby-forum.com/attachment/6505/_subcomment.html.erb -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.