Solved

Jquery apply jquery to elements after Ajax load

Posted on 2010-08-22
3
355 Views
Last Modified: 2013-11-11
Hi I have the following fragment of code, Once the content has been loaded the people_content function is called, but it does not apply the hide function to the elements called tabs. I suspect it is because it being loaded by ajax.
Any clues?

$('.choose_people').click(function(e){
    person_id=$(this).val();
    url=$(this).parent().attr('action');
    $('#people_content').load(url+'/'+person_id+'/modal',function(){
        ajaxloadergif(true);
    });
        ajaxloadergif(false);
        
    e.preventDefault();
    people_content();
})

function people_content(){
    $('#people_content','.tabs').hide();
}

Open in new window

0
Comment
Question by:jdav357
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 400 total points
ID: 33497552
What about :


// wait end of ajax call before calling people_content
	$('.choose_people').click(function(e){
		person_id=$(this).val();
		url=$(this).parent().attr('action');
		$('#people_content').load(url+'/'+person_id+'/modal',function() {
			ajaxloadergif(true);
			people_content();
		});
		ajaxloadergif(false);	
		e.preventDefault();
	})
	
	function people_content(){
		$('#people_content','.tabs').hide();
	}

Open in new window

0
 
LVL 15

Assisted Solution

by:SRigney
SRigney earned 100 total points
ID: 33502392
leakim971 has it right, you need to use the callback function that waits until the page is complete before calling the people_content function.

You could also just call the mehtod.  Another method would be to set the style of that html to hidden when it's loaded.  That may prevent a flicker that will occur from time to time if you rely completely on jQuery to hide the section.
'.choose_people').click(function(e){
		person_id=$(this).val();
		url=$(this).parent().attr('action');
		$('#people_content').load(url+'/'+person_id+'/modal',function() {
			// the load method is complete.
                        ajaxloadergif(true);
			$('#people_content','.tabs').hide();
		});
		ajaxloadergif(false);	
		e.preventDefault();
	})

Open in new window

0
 
LVL 82

Expert Comment

by:leakim971
ID: 33509462
Thanks for the points!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can i get the length? 7 31
how can i count words? 2 42
What am I doing wrong with this Lightbox widget? 6 33
Call a function within the ASP code 4 9
Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question