Try to cache/store the jQuery object if you can, instead of querying
for it several times. Also try giving a context to search in when
searching by class name like this:
var context = $('#parent').get(0); // Could also just use [0] to get
the DOM Element
$('div.recentposts', context);
context (Element): A DOM Element, or Document, representing the base context.
--
Brandon Aaron
On 12/8/06, Tim Baxter <[EMAIL PROTECTED]> wrote:
> Hi all, new to the list, new to jquery, getting my feet wet.
>
> I've got a script that I could use some help fine-tuning and optimizing, and
> I'm hoping you all can help. The script is used to collapse forum topics and
> can be seen in place at
> http://gretschpages.com/forum/modern-gretsch-guitars/
>
> ShowLatest() is a helper function that moves the first item up in the tree
> so it's still visible after the collapse.
>
> If the user has set a preference to collapse threads, a bit of on-page js
> will call collapse() and set collapsed=true, otherwise, it's a
> link-activated toggle. Profiling it in firebug, it looks like this thing is
> working pretty hard, though.
>
> Here's the script. Any suggestions to clean it, lean it, or otherwise
> improve are welcomed.
>
> var collapsed = "false";
>
> function showLatest() {
> $(".recentposts").find("a:eq(0)").each(function(i){
> lastpost = $(this).clone();
> $(lastpost).html(" »");
> $(lastpost).addClass("lastpost");
> theParent =
> $(this).parent().parent().parent().prev();
> $(theParent).append($(lastpost));
> });
> }
>
> // called if user preference is for collapsed:
> function collapse() {
> $(".recentposts").hide();
> $("#collapser").html("Expand All topics");
> showLatest();
> collapsed = "true";
> }
>
> //document.ready:
> $(function() {
> if (collapsed == "false") {
> $("#collapser").toggle(function(e) {
> e.preventDefault ();
> $(".recentposts").animate({
> height: 'hide',
> opacity: 'hide'
> }, 'slow');
> $(this).html("Expand All topics");
> showLatest();
> }, function() {
> $(".recentposts").animate({
> height: 'show',
> opacity: 'show'
> }, 'slow');
> $(this).html("Collapse All topics");
> $(".lastpost").remove();
> });
> } else {
> $("#collapser").toggle(function(e) {
> e.preventDefault();
> $(".recentposts").animate({
> height: 'show',
> opacity: 'show'
> }, 'slow');
> $(this).html("Collapse All topics");
> $(".lastpost").remove();
> }, function() {
> $(".recentposts").animate({
> height: 'hide',
> opacity: 'hide'
> }, 'slow');
> $(this).html("Expand All topics");
> showLatest();
> });
> }
> });
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
>
>
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/