ebolt007 0 Newbie Poster

Ok, so I have a bunch of scripts that I created, and by themselves they work perfectly, but I am trying to use a load more script, basically like I have below. Now the problem is I have put all of my "scripts" into a load more div, because if I only have them in the header and don't load them eachtime my script loads, then the scripts inside that "replaceWith" don't run at all, I guess because they become dynamic? Even tho they are in the header and should be global. Or maybe it's because each script runs when the document is ready function, and since the DOM is only set when it loads, then it doesn't pick up the scripts on a new AJAX reuest? Anyway, how would I clear all of the scripts basically and make sure they run after a new script is run? Either any new scripts aren't run if I only have the scipts in the header, or if they are loaded like below, then any previous scripts that are on the page duplicate each time another script is run. For instance, I have comments on my page with a like button on each comment, if I create a new comment, this appends to the bottom of my comments list, but then if I don't replace(reload) these scripts then the Like doesn't work unless the page is reloaded, but if I do replace these scripts like below then I hit Like, it Likes things twice, now if I make another comment and hit like, then it'll make like show up 3 times etc. So it's like the scripts don't clear on earlier scripts, and don't load on new scripts unless it's pulled in each time. Is it because of the ducument ready? because this has to run on ready, but it also has to run each time an ajax request is run, but not duplicate itself. Hope that makes sence.
Thanks for any help.

$(document).ready(function(){
            $("#loadmorebutton").click(function (){
                $('#loadmorebutton').html('<img src="/main-site-images/ajax-loader2.gif" />');
                $.ajax({
                    url: "loadmore.php?lastid=" + $(".postitem:last").attr("id"),
                    success: function(html){
                        if(html){
                            $("#postswrapper").append(html);
                            $('#loadmorebutton').html('Load More');
                                $("#loadwall").replaceWith('<div id="loadwall"><script src="js/wall.js" type="text/javascript" charset="utf-8"><\/script><script type="text/javascript" src="js/ajax-comment.js"><\/script><script type="text/javascript" src="js/ajax-like.js"><\/script><script type="text/javascript" src="js/ajax-unlike.js"><\/script><script type="text/javascript" src="js/ajax-likepost.js"><\/script><script type="text/javascript" src="js/ajax-unlikepost.js"><\/script><script type="text/javascript" src="js/ajax-deletecomment.js"><\/script><script type="text/javascript" src="js/ajax-deletepost.js"><\/script><script type="text/javascript" src="js/ajax-hidepost.js"><\/script><script type="text/javascript" src="js/ajax-hidecomment.js"><\/script><script type="text/javascript" src="js/ajax-statusupdate.js"><\/script></div>');
                        }else{
                            $('#loadmorebutton').replaceWith('<div class="nomore">No more posts to show.</div>');
                        }
                    }
                });
            });
        });
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.