How to link to specific anchor in table with jquery
I am using this jquery plug开发者_如何学Goin:
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!
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();
});
精彩评论