jQuery tabs. Open certain tab from a certain position. Possible?

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?

Answers


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.


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).


Need Your Help

Automated Unit Testing on Time based calculations

c# visual-studio-2010 unit-testing tdd

I have a small project which does some statistical calculations on the trades with inputs like Symbol, Price, time etc., I am using Visual Studio unit testing tools which is sufficient in case I do a

javascript grid sort by number, ordering issue

javascript sorting grid

I have a JS sort script, but is ordering #'s like this: