Jquery - event does not work on the newly created element

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

Answers


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


Need Your Help

Imporing large sql file with extended inserts to mysql using PHP?

php large-data mysqlimport

I am having issue when I am trying to import large sql file around 500MB. It has 100,000 extended inserts queries. I have serached every where but nothing found yet.

Grails one-many mapping stalestaleexception on composite key

hibernate grails gorm

I use grails 2.0.0. I have three objects Member, Product and ProductType. Member has many Products and is a one-to-many relation. Product points to ProductType (reference table) and is a many-to-one

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.