I've got a jQuery script that makes links open in a new JavaScript window, to show a page of content regarding jargon. However, that content is now being moved into a UI tab in the current page, instead. I want to modify my script to activate the tab and then jump down to an element with an ID that corresponds to the heading for the jargon section I want to show. I can activate the tab okay, but I just can't get the browser to jump to the content I want to highlight. Here's the function as it currently stands:
self.jargonWindow = function (url) // Jargon popup window { //window.open (url, 'Jargon', 'width=647,height=680,scrollbars=yes,resizable=yes').focus (); self.tabSet.tabs ('select', '#jargon-buster'); var target = url.split ('#').pop (), offset = $('#' + target).offset (); $(document).scrollTop (offset.top); return (false); }; The function triggers the jargon tab, then gets the fragment (the part after the # character) and tries to scroll to an element with that ID. The offset value I get for the target element, however, doesn't seem to be correct. I arranged the function so that the offset request happened after the tab activation, and when I enter the scrollTop command into the FireBug console while the jargon tab is being displayed the browser jumps to it as expected. This leads me to suspect that the tab doesn't really become visible until after the function has run, resulting in an incorrect for offset (). Has anyone got an idea for getting around this problem?