First, a thousand pardons! I see several threads that kinda' address my question, but they're all a little over my head. On the makeGreen function below, is this an acceptable way to implement an internal function? If I'm guessing right, we're operating on an object, so arguments are passed by reference, and this is NOT a memory leak? (function(jQuery){ jQuery.fn.ajaxMemo = function(options){ var defaults = { receivingPage: '/ajax/async-home.php' }; var options = $.extend(defaults, options); return this.each(function(){ var obj = $(this); makeGreen(obj); }); function makeGreen(obj){ obj.click(function(){ obj.css("backgroundColor","green"); }); } }; })(jQuery);
Thanks for Viewing, I have one page that locks up all browsers except Mac/Safari. It was more complex, but I whittled the jQuery code down to the bare essentials. Even though it's super-simple now, it still hangs for 15 seconds (FireFox is completely non-responsive during this) and ends with a script loop error message. Basically, I have a table where users click on a table row to direct them to that entry's page. (I put the href in the <tr> title attr) What in the world is wrong here? <script src='js/jquery.js' type='text/javascript'></script> <script type='text/javascript'> //<![CDATA[ $(document).ready(function(){ $("#target tr").click(function(){ var title = $(this).attr("title"); window.location.href = title; }); $(".hideinit").hide(); $("#ajax-load-img").hide(); }); //]]> </script>
Hi, I want to add your typical 'Loading' animated gif to a page while it's updating via ajax. I'm trying to do this in the $.displayCal function below. The $('div#load-wait') element is a div with the img inside. When the page initially loads, I don't see the image at all, even when $.post takes awhile to load. I see the image if I comment out $ ('div#load-wait').hide(); The problem, I'm guessing, is that the image is being hidden before $.post has a chance to finish. I know there's an easy solution w/o having to resort to setTimeout, but I can't figure it out. Thanks!! [code] var curlink; $.setup = function(){ $('a[rel*=facebox]').facebox(); $("a.cal-changedate").click(function(){ $.displayCal($(this).attr("rel")); }); } // make rpc call / response $.displayCal = function(fDate){ $("div#load-wait").show(); $.post( "/async/ajax_calendar.php", {"date": fDate}, function(data, textStatus){ if(textStatus == "success"){ $("#event-cal").html(data); $.setup(); }else{ alert("Oops! Communication errors."); } }); $("div#load-wait").hide(); }; var today = parseInt(new Date().getTime().toString().substring(0, 10)); $.displayCal(today); [code]