javascript - Help me diagnose this jQuery loop / Bookmark Hash problem? -


i'm having trouble getting jquery render correctly 100% of time - code using located below. purpose "simulate" feel of threaded forum hiding subject of replies - when subject clicked, 1st post replaced reply.

you can see example of in action here:

http://bulldogsworld.com/general-bulldog-chat/50-lbs-bulldog-one-shin-pic

the problem script doesn't work when people land via bookmark # in url, such as: http://bulldogsworld.com/general-bulldog-chat/50-lbs-bulldog-one-shin-pic#comment-1627028

specifically, problem happens reason posts below bookmark entry point replicated twice. can't figure out why happening - thoughts?

i'm pulling hair out on 1 - / guidance appreciated!

function flip(comment) { $('#first-post').replacewith(comment.closest(".comment").clone().attr('id','first-post')); $('#first-post').children('.forumthreadtitle').children('.comment-info').empty(); $('#first-post').find(':hidden').fadein('slow'); $('html, body').animate({scrolltop:0}, 'fast'); return false; }  $(document).ready( function(){   $('.submitted').each(function() { $(this).clone().addclass('comment-info').appendto($(this).siblings('.forumthreadtitle')); if(!$(this).parent('#first-post').html()) {     $('#first-post').children('span.taxonomy').clone().appendto($(this));     } });  $('.display_mode').html('show replies'); expandedmode = false; $('.display_mode').click(function() {     if ( expandedmode  == false  ) {         $('.forumthreadtitle').siblings().show();          $(this).html('collapse replies');         expandedmode  = true;         }     else         {         $('.forumthreadtitle').siblings().hide();         $(this).html('show replies');         expandedmode = false;          }     });  $('.forumthreadtitle').siblings().hide();  if(window.location.hash) {         flip($(window.location.hash).nextall().children('.forumthreadtitle').show());         }  $('.forumthreadtitle').click(function() {      pagetracker._trackpageview("/comment?page=" + document.location.pathname);     flip($(this));      } ); }); 

you need use next() instead of nextall() in flip

flip($(window.location.hash).next().children('.forumthreadtitle').show()); 

nextall() returns elements after selected, , passed flip function.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -