views:

68

answers:

1

Hello,

I have a simple comment section where users can post comments to another users post - It works pretty much in the style of facebook wall where a user can write something on the wall and other can comment on it.

So I have this form where the user can enter anything and when he submits - that information is inserted in the database and shown on the same page below the form using Jquery.

Now each of these post have a comment link next to it. So when someone clicks on the comment link - a small textarea box appears where the user can type something and submit.

Everything works great on the previously posted items- except that the comment link on the newly created element does not open up the textbox area.

After searching I came across the Livequery plugin which I implemented - but that doesn't seem to work for me - looks like I'm doing something wrong.

This is the code that I had previously:


    $(".comment_button").click(function(){                           
                var element = $(this);
                var I = element.attr("id");
                //alert("in="+I);; 
                $("#slidepanel"+I).slideToggle(300);
                $(this).toggleClass("active");
                return false;
            });

I changed this to use livequery:


   $('.comment_button').livequery('click',function(event) {                
                var element = $(this);
                var I = element.attr("id");
                //alert("in="+I);; 
                $("#slidepanel"+I).slideToggle(300);
                $(this).toggleClass("active");
                return false;
            });

This is the link for comment

<a id="<?php echo $data['shopping_id']?>" class="comment_button" href="<?php echo $data['shopping_id']?>">Comment</a>

Thanks for your tips

+2  A: 

You don't need livequery, just live. Replace livequery with live and it should work fine.

Skilldrick
Thanks Skilldrick - I tried with live - it still does'nt do anything - the event is being called - cos the alert shows up and displays the right ID - but the $("#slidepanel"+I).slideToggle(300); does not seem to be workingThanks
Gublooo
What is the id displayed? I think the problem may be in `$("#slidepanel" + I)` - it looks like you may need a space there.
Skilldrick
The ID displayed is the id of the last comment posted.The slidepanel code is fine because it works - when your refresh the page and click on the "Comment" link for previous post.It doesn't work only for the newly created element. Do we need to rebind the slidepanel as well
Gublooo
Can you post the id displayed? I can't work out exactly what's going on, but if `I` is a child element of `#slidepanel` then the jQuery selector should be `"#slidepanel #" + `I`
Skilldrick
@Skilldrick don't bother to help him since he doesn't bother to accept a question
c0mrade
Ok maybe I am not doing it the right way - Let me explain to you.A user can submit a POST identified by the SHOPPING_ID. Now each post (SHOPPING_ID) can have several comments. The comment link appears next to each POST. When user clicks on the comment link - a text box shows up. - slidepanel is a seperate div element which contains the textarea where the user can type in comments for a particular post (SHOPPING_ID)- It is shown and hidden when the user clicks on "Comment" link. It is not a child element of ahref of the COMMENT link.
Gublooo
So the code above is called - when the user clicks on the "Comment" link - the slidePanel is the DIV that is supposed to show up which contains the text area.So the "I" refers to the main SHOPPING_IDThis is the slidepanel DIV element<pre><code><div id="slidepanel<?php echo $data['shopping_id']; ?>"><div> <textarea id="sayit<?php echo $data['shopping_id']?>" ></textarea> </div><div><input class="comment_submit" id="<?php echo $data['shopping_id']?>" type="submit" value="Say it"/> </div></div></code></pre>
Gublooo
@c0mrade - I am new to this site - What do you mean he doesn't bother to accept a question. Am I supposed to do something which i'm not doing. If it is please let me know as it is unintentional as I'm not aware of the practices on this site.Thanks
Gublooo
@Gublooo you should accept some questions first, you have 5 questions without accepted answer, I'd recommend that you read http://stackoverflow.com/faq first
c0mrade
Thanks c0mrade :) - just accepted all my previous questions
Gublooo