Jump to content

jquery load function


funbinod
 Share

Recommended Posts

hi guys!

I loaded data from another page using click function by d following code..

<script>$(document).ready(function(e) {	$("#suncrlink").click(function(e) {		$("#suncr").load("ajax/suncr.php?m=8");	});</script>

I worked. but I wish if I could unload (or hide) the loaded data when I click the same link again or not!

 

can anyone guide...

Link to comment
Share on other sites

  • 3 weeks later...

Using a anonymous function as you suggest runs as soon as it is encountered,if the elements it is targeting have not been rendered yet! An undefined error will occur cause the element in question does not exist. On the otherhand if used as $(function(){}); which is just shorten method of $(document).ready(function(){}); it targets the specific element AFTER the page has fully loaded.

Link to comment
Share on other sites

//you dont need the put a function in the "$(document).ready". Use an anonymous function instead.<script>(function(){ //anonymous function$("#suncrlink").click(function(e){$("#suncr").load("ajax/suncr.php?m=8");});});</script>

This is not a very good idea. Waiting for the DOM to be ready before manipulating it is the preferred way, in fact.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...