After the 4th <a> element is found, how would I .hide() the rest? Below is the code I’ve written so 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:
Or the faster
slicefunction:Live DEMO