SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Apr 2012
    Location
    Los Angeles, CA
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Applying jQuery to AJAX'd Content

    I'm having some problems and wanted to see if anyone knew how to resolve my issues. I'm using fancybox to call another page. Everything returns fine except i need the tinyscrollbar to apply to the content returned in ajax so that the user can scroll to view the complete content. I've tried using .on but not sure if i'm doing it right. i've used the following codes:

    Code JavaScript:
    $(document).ready( function() 
    {
    	$("a.lightbox").fancybox({
    		'titlePosition'		: 'inside',
    		'transitionIn'		: 'none',
    		'transitionOut'		: 'none'
    	});
     
    	$("a.lightbox").on( 'load', function() {
    		$('#scrollable').tinyscrollbar();
    	});
     
    });

    and

    Code JavaScript:
    $(document).on("click", "a.lightbox", function() {
    	alert( 'hello' );
    	$('#scrollable').tinyscrollbar();
    });

    Neither work. If i add an alert then it seems to work:

    Code JavaScript:
    $(document).ready( function() 
    {
    	$("a.lightbox").fancybox({
    		'titlePosition'		: 'inside',
    		'transitionIn'		: 'none',
    		'transitionOut'		: 'none'
    	});
     
    	$("a.lightbox").on( 'load', function() {
    		alert( "hello world" );
    		$('#scrollable').tinyscrollbar();
    	});
     
    });

    Any one know how to get jquery to apply to the ajax'd content?

  2. #2
    SitePoint Addict tlacaelelrl's Avatar
    Join Date
    Apr 2011
    Location
    Mexico city, Mexico
    Posts
    353
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    As far as I know the 'load' won't work but correct me if I'm wrong, your functions would work if you remove the load and add 'click' check http://jsfiddle.net/g7M3s/]this as it is a sample of the anchor being selected by it's class name, if you click the anchor you will get the alert
    Do you get bothered because I do the same thing every day?
    Do you question why I do it?
    Then find something that you actually like doing!!!

    Stop thinking on what I do.

  3. #3
    SitePoint Member
    Join Date
    Apr 2012
    Location
    Los Angeles, CA
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yea it didn't. I did finally get it to work using fancybox's onComplete. Now that fixed what i needed to do.

    Code JavaScript:
    $(document).ready( function() 
    {
        $("a.lightbox").fancybox({
            'titlePosition'        : 'inside',
            'transitionIn'        : 'none',
            'transitionOut'        : 'none',
            'onComplete'        : function() {
                $('#scrollable').tinyscrollbar();
            }
        });
    });


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •