I am assuming your original code looked similar to the following:
$('table').on('click', '.use-address', function() {
var $row = $(this).closest("tr"); // Find the row
var text = $row.find(".nr").text().trim(); // Find the text
console.log(text);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tbody>
<tr>
<td class="nr"><span>50</span>
</td>
<td>Some Street 1</td>
<td>
<button class="use-address"> Test </button>
</td>
</tr>
<tr>
<td class="nr">49</td>
<td>Some Street 2</td>
<td>
<button class="use-address"> Test </button>
</td>
</tr>
</tbody>
</table>
You should avoid declaring variables with leading $
(dollar signs), unless the value they hold is an actual jQuery element.
The equivalent would be the following:
const handleClick = ({ target }) => {
if (target.classList.contains('use-address')) {
const row = target.closest('tr');
const text = row.querySelector('.nr').textContent.trim();
console.log(text);
}
};
document.querySelector('table').addEventListener('click', handleClick);
<table>
<tbody>
<tr>
<td class="nr"><span>50</span>
</td>
<td>Some Street 1</td>
<td>
<button class="use-address"> Test </button>
</td>
</tr>
<tr>
<td class="nr">49</td>
<td>Some Street 2</td>
<td>
<button class="use-address"> Test </button>
</td>
</tr>
</tbody>
</table>
Checkout "You might not need jQuery" to see some examples of equivalent plain JS code.