funbinod Posted October 5, 2014 Share Posted October 5, 2014 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 More sharing options...
dsonesuk Posted October 5, 2014 Share Posted October 5, 2014 Why not use toggle() http://api.jquery.com/toggle-event/, with first click load, and second hide or remove whatever. 1 Link to comment Share on other sites More sharing options...
funbinod Posted October 5, 2014 Author Share Posted October 5, 2014 thank u! it worked using toggle Link to comment Share on other sites More sharing options...
kodejuice Posted October 26, 2014 Share Posted October 26, 2014 //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> Link to comment Share on other sites More sharing options...
dsonesuk Posted October 26, 2014 Share Posted October 26, 2014 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 More sharing options...
thescientist Posted October 27, 2014 Share Posted October 27, 2014 //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. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now