I have a table with some values. I am getting the current selected value from a jQuery click event as shown below.
When I click 1 I get 1 in console. When I click 2 I get 1 and 2 both.
When I write $(selectedValue).remove() it doesn't work. Also it doesn't work if I write $(selectedValue).text()
I just want the value 2 in console i.e. I want to replace the old value with a newly clicked (or selected) value.
$('td').click(function() {
var selectedValue = $(this).text(); // get the current cell text
$(selectedValue).remove(); //this doesn't reset the value
var row = $(this).parent().text();
console.log(selectedValue);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<th>First</th>
<th>Second</th>
<th>Third</th>
</tr>
<tr>
<td>0</td>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
</table>