views:

26

answers:

2

I am using jQuery tabs on my site and have an article on one of the tabs and comments on the other. Would it be possible to link from the article tab to the comments tab and open it from a certain position defined with an "a name" attribute?

A: 

Since the tab itself needs to be selected with the hash anchor, you probably can't do it in a straightforward way.

One way to do it though, would be to parse the anchors yourself (with anchors not set to the tab names, but for example tab-name:anchor-name) and then select the correct tab (using the jQuery Tabs API) and scroll to the correct anchor (using javascript).

Tomas Lycken
A: 

The jQuery UI 1.8.4 release added a feature you may be interested in:

TABS
The tabs plugin has been updated to allow accessing tabs by href in addition to index. The enable, disable, select, load, and remove methods all accept the href of a tab.

For example, what you want may look like this:

$("#tabs").tabs("select", "#comments");

For the scrolling you can just do a window.location or use something else like the scrollTo() plugin for more utility.

For example:

$("#tabs").tabs("select", "#comments");
$("#comments").scrollTo("#comment-1234");

You can give it a try here.

Nick Craver