Get last visible element using jQuery

html, javascript, jquery

Solution

There are different jQuery Selectors for those purposes.

For example:

$('table tr:visible:last').attr('number');

or

$('table tr:visible').last().attr('number');

and so on.

Full code

$('#check').click(function() {
    check = $('table tr:visible:last').attr('number');
    alert(check);
});

DEMO

Problem

``` <table> <tr class="here" id="t1" number="1" ><td>1</td></tr> <tr class="here" id="t2" number="2" ><td>2</td></tr> <tr class="here" id="t3" number="3" style="display:none"><td>3</td></tr> <tr class="here" id="t4" number="4" style="display:none"><td>4</td></tr> </table> <span id="check">check</span> $('#check').click(function(){ check = ???; alert(check); }) ``` DEMO: http://jsfiddle.net/vUukc/1/ How can I get the attribute `number` from last visible `tr` in this example? This is an example - all `<tr>` could be visible.

Original source