2

I was checking a few sites, and I came up with the below:

    <table class="admin_table">
        <thead>
            <tr>
                <th>Company Name</th>
                <th>Industry</th>

            </tr>
        </thead>
        <tbody>
            <tr url="/home/companies/1">
                <td>Microsoft</td>
                <td>Computer Software</td>
            </tr>
        </tbody>
    </table>

$(document).ready(function() {
    $(".admin_table tr").not(':first').click(function() {
        var url = $(this)..attr("url");
        if (url != null && url != '') {
            window.location = url;
        }
    });
});

However, when clicking on the row, it's not responding?

I initially read the following sites for this:

jQuery - Click event on <tr> elements with in a table and getting <td> element values

Making a Table Row clickable

http://www.electrictoolbox.com/jquey-make-entire-table-row-clickable/

Is there anything I am missing in my code? In many cases the code is identical...

3
  • There supposed to be .. (two dots) after $(this)? Commented Aug 15, 2012 at 22:16
  • If I remove the two dots after $(this) it works for me. See jsfiddle.net/WbqFj Commented Aug 15, 2012 at 22:17
  • wow...how did I completely miss that. Works now. Commented Aug 15, 2012 at 22:17

1 Answer 1

3

Ofcourse only the second row should work, since that is the one with the url. But first you should remove the double dots $(this).attr('url');

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.