JSFiddle - React, Tailwind, and code Playground
HTML
<div id="lse" class="display">
<div id="centertbl">
<table id="tblData" class="TSS">
<tr>
<td align="center" colspan="4"><b>Table 1</b></td>
</tr>
<tr>
<td align="center" colspan="4" id = "1">Data 1</td>
</tr>
<tr>
<td align="center" colspan="4" id = "2">Data 2</td>
</tr>
<tr>
<td align="center" colspan="4" id = "3">Data 3</td>
</tr>
<tr>
<td align="center" colspan="4" id = "4">Data 4</td>
</tr>
</table>
<table id="tblData" class="TSS">
<tr>
<td align="center" colspan="4"><b>Table 2</b></td>
</tr>
<tr>
<td align="center" colspan="4" id = "5">Data 1</td>
</tr>
<tr>
<td align="center" colspan="4" id = "6">Data 2</td>
</tr>
<tr>
<td align="center" colspan="4" id = "7">Data 3</td>
</tr>
<tr>
<td align="center" colspan="4" id = "8">Data 4</td>
</tr>
</table>
</div>
<p class='info'>
</p>
<input type="submit" class="button button1" name="submitButton" value="Button 1">
<input type="submit" class="button button1" name="submitButton" value="Button 2">
</div>
CSS
.TSS {
border: 1px solid #000000;
float: none;
font-family: Verdana, Geneva, sans-serif;
font-size: 10.6px;
font-style: normal;
padding: 10px;
text-decoration: none;
display: inline-block;
}
#centertbl {
text-align: center;
}
.button {
background-color: #4CAF50;
/* Green */
border: none;
color: white;
padding: 5px 15px;
text-align: center;
text-decoration: none;
display: block;
font-size: 16px;
margin: 4px 2px;
-webkit-transition-duration: 0.4s;
/* Safari */
transition-duration: 0.4s;
cursor: pointer;
}
.button1 {
background-color: white;
color: black;
border: 2px solid #4CAF50;
}
.button1:hover {
background-color: #4CAF50;
color: white;
}
.clicked {
border: 1px solid red;
}
JavaScript
$('td').on('click',function(){
$(this).toggleClass('clicked');
console.log('hi!');
});
$('.button.button1').on('click',function(){
$( "td.clicked" ).each(function() {
console.log($(this).attr('id'));
var a = $(this).attr('id');
$('.info').append(' Element id is: ' + a);
});
});