Bug Tracker

Modify

Ticket #11259 (closed bug: invalid)

Opened 16 months ago

Last modified 16 months ago

.on() Not Working After Different Content Loaded

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

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

comment:1 Changed 16 months ago by rwaldron

  • Status changed from new to closed
  • Resolution set to invalid

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

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.