How can I add an onclick event in JavaScript to navigate to a URL when a user clicks on an element?

Yep, totally agree with Dimple used that approach myself. But if you’re working with dynamic destinations (like different rows leading to different detail pages), here’s a slightly more flexible approach I use in one of my dashboards.

You can store the target URL in a data-url attribute on each <tr>:

<tr data-url="read_message.php?id=123">...</tr>
$('tr').click(function () {
    const targetURL = $(this).data('url');
    if (targetURL) {
        window.location.href = targetURL;
    }
});

This makes the script reusable across all your rows, each pointing to its own destination. It’s a dynamic and clean way to handle javascript navigate to url behavior without hardcoding links in the JS.