having a slight problem here. I have a post stream on my site, each post has buttons that execute different actions that are setup in my $(document).ready() now, to add posts I make an AJAX call that returns the html for the new post element, but the actions in the my previous $(document).ready() do not apply to this new element, and adding it in a $(document).ready() for the element causes the buttons from the already posted elements to be duplicated.
Any idea how I can get around this?
The elements that added after documnet ready event don’t accept binding events (you call it ations). You may use
.click()or.hover()or.bind('click', function(){})and neither works. You can use jQuery.live()or.delegate()Using
delegateis much better because when you useliveforclick(for example) it means you’r listening to anyclickhappening on your document and determining if it’s thatclickyou where looking for or not? But withdelegateyou limit the clicks that computer process to find yourclick.