1

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

Skilldrick
  • 69,215
  • 34
  • 177
  • 229
Gublooo
  • 2,550
  • 8
  • 54
  • 91

1 Answers1

2

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

Skilldrick
  • 69,215
  • 34
  • 177
  • 229
  • 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 working Thanks – Gublooo Feb 27 '10 at 13:02
  • 1
    What is the id displayed? I think the problem may be in `$("#slidepanel" + I)` - it looks like you may need a space there. – Skilldrick Feb 27 '10 at 13:14
  • 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 Feb 27 '10 at 13:32
  • 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 Feb 27 '10 at 13:37
  • @Skilldrick don't bother to help him since he doesn't bother to accept a question – ant Feb 27 '10 at 13:51
  • 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 Feb 27 '10 at 13:53
  • 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_ID This is the slidepanel DIV element
    
    
    – Gublooo Feb 27 '10 at 13:54
  • @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 Feb 27 '10 at 13:55
  • @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 – ant Feb 27 '10 at 14:18