I'm using onClick in table rows as follows:
<tr onmouseover="this.style.cursor='pointer'" onclick="http://www.whatever.com/index.php?var={$foo1}">
I also have some needs to put a link in certain areas in this table row, i.e.
<td>Stuff Here</td>
<td>Stuff Here</td>
<td>Stuff Here</td>
<td><a href="specialLink.php?var={$foo2}">Here</a></td>
<td>Stuff Here</td>
The problem is, the "inner link" (specialLink.php) can't be clicked, because the row link takes precedence. Do I have any options here?
Thanks
To make the entire row as clickable in this case, one can use a link <a> tag to wrap its content.
Using onclick Event: The onclick event attribute works when the user click on the button. When mouse clicked on the button then the button acts like a link and redirect page into the given location.
To make the full row selectable, you should add the link to the <tr> instead of to individual table cells. Since you're not allowed to place an <a> tag around a table row, you'll have to think a little bit outside the box to solve this puzzle.
If you add "display: block" CSS style tag to the anchor objects in the cells that you want to be clickable it will make the entire cell (minus any padding) act like a button. The cursor is displayed correctly and it previews the link destination in the status bar.
You can use stopImmediatePropagation() to bypass consecutive/incoming events.
Short example:
<tr onclick="alert('tr event')">
<td>tr event</td>
<td onclick="alert('td');event.stopImmediatePropagation();">NO tr event</td>
</tr>
Test this on jsfiddle: http://jsfiddle.net/g8Anh/6/
I 'll do that :
<script type="text/javascript">
var link=true;
</script>
<tr onmouseover="this.style.cursor='pointer'" onclick="if (link) window.location ='http://www.whatever.com'">
<td>Stuff Here</td>
<td>Stuff Here</td>
<td>Stuff Here</td>
<td onmouseover="link=false;" onmouseout="link=true;"><a href="specialLink.php">Here</a></td>
<td>Stuff Here</td>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With