Solved

Cannot hide loaded HTML using JQuery/AJAX

Posted on 2014-09-22
2
277 Views
Last Modified: 2014-09-23
I am using JQuery/AJAX to load some HTML data but I then want to apply a JQuery method to hide some of the loaded HTML. Unfortunately the JQuery method does not seem to apply to the loaded HTML.

Here is a simple file I am loading:
http://www.dressorganic.co.uk/ajaxonload/filetoload.htm

Here is the page to load the file:
http://www.dressorganic.co.uk/ajaxonload/test1.htm

If you view source you can see I load the file then immediately try to hide id "tohide" but nothing happens.

I am familiar with the JQuery "on" method but only know how to apply it on an interactive event such as click. For example:
$("body").on("click", ".link", function() {...

But I am not sure how to apply it immediately after loading.
0
Comment
Question by:mike99c
2 Comments
 
LVL 1

Accepted Solution

by:
Richard Francis earned 500 total points
ID: 40338514
You can use the callback function of the .load event to hide the content:

	$(document).ready(function(){
				
	    $('#receivingcontainer').load('/ajaxonload/filetoload.htm #datacontainer', function() {
  			$('#tohide').hide();
		});  
	                              
    });

Open in new window


edit: Sorry I should also have given you the link to the relevant jQuery doc, so here it is http://api.jquery.com/load/
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40338962
add a bit of CSS in your page, so by default it hidden :

<style>
#tohide {
    display:none;
}
</style>

Open in new window

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

867 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

15 Experts available now in Live!

Get 1:1 Help Now