Solved

Jquery apply jquery to elements after Ajax load

Posted on 2010-08-22
3
375 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

Question has a verified solution.

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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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…
Suggested Courses

622 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