Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

overriding tr onclick

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?

like image 602
synic Avatar asked May 29 '11 21:05

synic


1 Answers

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

like image 151
Mark Avatar answered Oct 12 '22 13:10

Mark