Solved

Jquery apply jquery to elements after Ajax load

Posted on 2010-08-22
3
351 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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 Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now