views:

1056

answers:

2

I am building a site and I have a list of status updates and I want to allow the users to write comments for each of of the items in the list

However I am trying to implement a UI similar to the way stack overflow works specifically the collapsible comment form / list where a user clicks on add comment on the specific status update in the list, and below that item in the list the comment entry form shows up along with the specific comments already posted.

How do I accomplish this using Jquery?

Note: looking also for the markup example another words a working sample. Thanks And yes if you could show Async postback that would be nice too

A: 

The quick approach (for just showing / hiding the comment area) would resemble something like this:

$(function(){
   $('#id_of_element_to_use_for_click').click(function(){
      $('#id_of_comment_area').slideToggle();
   });
});

The jQuery site will provide you with doco on different approaches such as fades, slides or other combined animations.

Your "Comment Area" I've used in the example here would likely be a <div> tag that contains your existing comments, plus whatever textarea or text input box you wanted users to type their answers into.

Do you need to do an asynchronous postback?

Phil.Wheeler
You forgot to wrap it in a $(document).ready(function(){}); (I didn't - you, however)
Will
$(function(){});==$(document).ready(function(){});
redsquare
I guess the json xhr call and the callback to build the html fragment is also important
redsquare
WTF???You don't need the formal syntax, you moron. $(function()... is exactly the same as $(document).ready(function()... Also, I said in my answer that this is a quick approach. I don't pretend to deal with asynchronous postback. That would be why I asked if the user wanted more info.
Phil.Wheeler
And another thing - since you two are so eager to downvote the only answer posted so far, perhaps you'd like to spend the time to provide the right one? Very constructive, folks.
Phil.Wheeler
-1, redsquare does make a good point, how does this answer address the need to load the comments? And you should not be offended with downvotes, they are for your answer not you.
Samuel
-1 for moron. Moron? Just because somebody didn't know some syntax that makes him/her a moron? Classic example of full of sh**-ness. Maybe it could have helped if you were polite and just told the person what follows moron.
Cyril Gupta
This is ridiculous!! I am the only one who has even attempted to answer this question so far, and rather than anyone saying "you've only answered it half-way", they're just taking the lazy option and downvoting what I've written.<cntd>
Phil.Wheeler
I can't believe that this simple question has turned into a mudslinging and character assassination forum. If you don't think the answer is complete, COMPLETE IT. Don't just bag me for not following through. Where the hell are everyone else's better ideas?!
Phil.Wheeler
Perhaps if Phil gave a bit more explanation i.e. gave an answer that imparted some information that people could learn from rather than a quick snippet that half solves the problem he would attract some of the up-votes he was after?
meouw
True, I'll add the rest during my lunch break tomorrow. But I wasn't suggesting my answer should by default be upvoted either. My argument is that the answer was not of such a poor quality as to be downvoted. It was only incomplete. Why not just not vote at all?
Phil.Wheeler
@Phil - I thought you could expand your answer rather than hijaking it and completing it. if you dont I will happily explain the missing steps to emulate how SO does it. No offence meant at all, it was merely to prompt you into maybe expanding the answer
redsquare
+2  A: 
sighohwell
Thanks this worked purrrrfectly.
dswatik