jquery - Hide all elements that come after the nth element -
after 4th <a> element found, how .hide() rest? below code i've written far:
<script src="http://code.jquery.com/jquery-latest.js"></script> <script> $(document).ready(function() { if($('a').length >= 4) { window.alert('4 or more'); } }); </script> <a>test </a><br> <a>fed </a><br> <a>fdes </a><br> <a>grr </a><br> <a>rerf </a><br> <a>dferf </a> any ideas?
use :gt(index) selector:
$('a:gt(3)').hide(); or faster slice function:
$('a').slice(4).hide(); because :gt() jquery extension , not part of css specification, queries using :gt() cannot take advantage of performance boost provided native dom queryselectorall() method. for better performance in modern browsers, use $("your-pure-css-selector").slice(index) instead.
Comments
Post a Comment