I have the following code:
<div id="comments">
<h2>
Comments</h2>
<div id="comment">
</div>
<% foreach (var comment in this.Model.Topic.TopicComments.OrderBy(tc => tc.CreatedDate).Reverse())
{ %>
<% this.Html.RenderPartial("TopicComment", comment); %>
<% } %>
<fieldset>
<% using (Ajax.BeginForm("AddComment", "Topic", new { id = this.Model.Topic.TopicId },
new AjaxOptions { UpdateTargetId = "comment", OnSuccess = "animateTopicComment" }))
{ %>
<%= Html.TextArea("Body", string.Empty, new { @class = "wmd-ignore" })%>
<input type="submit" value="Add Comment" />
<% } %>
</fieldset>
</div>
<script type="text/javascript">
function animateTopicComment() {
$("#comment").fadeOut(0, function() {
$( #comment ).fadeIn("slow");
});
$("#Body").val("");
}
</script>
What I am trying to do is whenever the user adds a comment I would like the comment to fade in. This almost works ... save for the following issue:
If I keep adding comments, whatever was in the comment DIV is overridden. If I don t use any of the jQuery animations the new comments appear correctly.