I create a button within the <td>
tag of a HTML table.
I've added a listener to trigger an alert on click event.
The <td>
tag of the HTML table is equally tight to an event listener and triggers an alert with a distinct text from the button on click.
The snippet below illustrates the scenario above.
$("#mytable").on("click", "td", function() {
alert('this is td');
});
$("#mybutton").on("click", function() {
alert('this is button');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<table id="mytable">
<tr>
<td style="border: 1px solid black; width: 500px; height: 20px">
<span>table</span>
<button style="margin: 5px; padding:5px; border: 1px solid black; float: right" id="mybutton"> display</button>
</td>
</tr>
</table>
How can I effectively make the click event on the button execute without triggering the click event of the <td>
tag in which the button is enclosed?