I have html tables.and I would like to change it's class by clicking itself.
When I change class,I would like to select each class by clicking button behind them
My attempt is like below. How can I pick up style by clicking on button?
Thanks
$('.click_btn').on('click', function(e) {
e.preventDefault();
style = $(this); ??
})
$('.click_td').on('click', function(e) {
e.preventDefault();
$(this).AddClass(style); ??
});
.style1{
background: rgb(255, 0, 255);
border-radius: 5px;
}
.style2 {
background: rgb(0, 255, 255);
border-radius: 5px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<td class="click_td">color</td>
<td class="click_td">color 2</td>
</tr>
</table>
<button class="click_btn" class="style1">style1</button>
<button class="click_btn" class="style2">style2</button>