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.
"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:
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
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.
> 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:
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.