<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.
To achieve the best performance when using :visible to select elements, first select the elements using a pure CSS selector, then use . filter(":visible") . Using this selector heavily can have performance implications, as it may force the browser to re-render the page before it can determine visibility.
Answer: Use the jQuery :visible Selector You can use the jQuery :visible selector to check whether an element is visible in the layout or not. This selector will also select the elements with visibility: hidden; or opacity: 0; , because they preserve space in the layout even they are not visible to the eye.
Syntax: $(element).is(":visible"); Example 1: This example uses :visible selector to check an element is visible or not using jQuery.
The :visible selector in jQuery is used to select every element which is currently visible. It works upon the visible elements. The elements that are consuming space in the document are considered visible elements. The height and width of visible elements are larger than 0.
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
$("table tr:visible:last").attr("number");
See the jQuery Documentation on Selectors for more info on the :visible
and :last
selectors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With