Reputation: 26678
I've got the following code in a django template:
{% for item in items %}
<tr onclick="{% url collection:viewitem item_id=item.id %}">
<td>{{ item.name }}</td>
<td>{{ item.date }}</td>
<td>
<button onclick="{% url collection:edititem item_id=item.id %}" type="button">Edit</button>
<button onclick="{% url collection:removeitem item_id=item.id %}" type="button">Remove</button>
</td>
</tr>
{% endfor %}
However, the button onclick
events don't work, because the tr onclick
seems to override it. How can I prevent this from happening?
Upvotes: 12
Views: 5855
Reputation: 131
An other approach: Create a separate row for the button so it wont inherit the tr onclick event of the main row. Something like this:
<tr onclick="doSomething()">
<td rowspan="2">A</td>
<td rowspan="2">B</td>
<td rowspan="2">C</td>
</tr>
<tr>
<td><button type="button">Click</button></td>
</tr>
Upvotes: 0
Reputation: 368
please try the following:
<html>
<body>
<table >
<tr onclick="alert('tr');">
<td><input type="button" onclick="event.cancelBubble=true;alert('input');"/></td>
</tr>
<table>
</body>
</html>
The event.cancelBubble=true will suppress the tr click event
Upvotes: 21