views:

60

answers:

1

I am using this jquery plugin:

http://www.jankoatwarpspeed.com/post/2009/07/20/Expand-table-rows-with-jQuery-jExpand-plugin.aspx

I have anchors in the code such as:

<a name="art" id="art2"></a> Articles

How can I open that particular row then? In other words, when a user clicks a link from another page to this landing page I would like the appropriate row to open up based on the anchor tag.

Thanks in advance!

+3  A: 

In your document.ready you can call the click event of that anchor, like this:

$(function() {
  if(document.location.hash != '')
    $(document.location.hash).click();
});

This would make for example www.yoursite.com/yourPage.htm#art2 perform a click on that link causing it to open. Just make sure the above code is after your click event handler, so it actually does something on click :)

If you're landing on #art using the named anchor, similar approach:

$(function() {
  if(document.location.hash != '')
    $('a[name="' + document.location.hash.replace('#','') + '"]').click();
});
Nick Craver
+1. But does `.hash` include the "#"?
Joel Potter
@Joel - Yep, I believe that's consistent across all browsers.
Nick Craver
I can't get that to work. Made a test page here:http://www.libraries.uc.edu/tests/table_rows.htmlSuch that your example would be:http://www.libraries.uc.edu/tests/table_rows.html#art2
LisaH
@LisaH - It's currently inside the click handler `$("#report tr.odd").click(function(){`, it needs to be moved outside of there, and no need for the `$(function() { });` around it since you're already in document.ready :)
Nick Craver
OK, cool- I think I got it- thanks so much!!
LisaH