Solved

Jquery apply jquery to elements after Ajax load

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

747 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

13 Experts available now in Live!

Get 1:1 Help Now