Bug Tracker

Opened 8 years ago

Closed 8 years ago

#11259 closed bug (invalid)

.on() Not Working After Different Content Loaded

Reported by: anonymous Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:

Description

jsFiddle: http://jsfiddle.net/grn2012/qRWa5/20/

If you go to http://www.elemovements.com and try clicking "Read more..." on the first article, it will work, along with if you click the same link in the archive. This is all taken care of by this block of code... it's messy, yes, but I've been trying to figure various ways of doing it.

( function() {
	
    // Unfortunately, this has to put down here because it needs to run
	// on both the archive and the news sections and it would be annoying
	// and redundant to call it every time those two are loaded.
	
	var $Body = $("#news .inner");
	var $Title = $("#news .title");
	
	var strNewsURL = "<?=URL_NEWS?>";
	var strOld = $Body.html();
		
    $(document).on("click", "#news a.more", function(event) {
    	
    	var strURL = $(this).attr("href").replace("index.php", strNewsURL);
        
		$Body.slideUp(100);
        
        $.get(
            
            strURL,
            
            objNHF,
            
            function(strData) {
				
                $Body.html(strData + '<a class="back"><?=TEXT_BACK?></a>').slideDown(1000, "easeOutBounce");
                
                $(document).on("click", "#news a.back", function(event) {
                    
                    $Body.slideUp(100, function() {
						
						$(this).html(strOld);
						
					} ).slideDown(1000, "easeOutBounce");;
                    
                    event.preventDefault();
                    
                } );
                
            }
            
        );
        
        track(strURL);
        
        event.preventDefault();
        
    } );
	
} );

If you try loading another page (let's say, "Contact"), then click "Home" again, the event fires but does not load the content into the div. What am I doing wrong here? Very puzzling.

Change History (1)

comment:1 Changed 8 years ago by Rick Waldron

Resolution: invalid
Status: newclosed

Please use the forum for support questions first: http://forum.jquery.com/getting-started

Note: See TracTickets for help on using tickets.