I want to make each row in a table respond to a mouse click. Specifically I want it to go to a link URL. At the moment my table is defined like this
<ul wicket:id="componentStatus" class="component-status">
<li wicket:id="equipComponentInst">
<table class="full-width">
<tr>
<td><div wicket:id="<XXX>ComponentPanel"></div></td>
<td><a wicket:id="<XXX>DetailLink" class="pull-right"><img wicket:id="detailLinkImg" border="0px"/></a></td>
</tr>
</table>
</li>
</ul>
As you can see, I have a <td>
element containing a link.
But I would like the link to be followed if the user clicks on any part of the table row.
According to this SO question, it's possible to define a Javascript click handler function for table rows.
So I added such a click handler like this in my Java code
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
response.render(OnLoadHeaderItem.forScript("$('tr').click( function() { window.location = $(this).find('a').attr('href');})"));
}
But the handler function never gets called. Can this work, or do I need to look at a different approach?