+ Reply to Thread
Results 1 to 3 of 3

Thread: Hide rest of elements that come after a specific element

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    14

    Hide rest of elements that come after a specific element

    I have list of <a> elements and i`d like to hide rest of elements that come after a specific element
    i used that javascript script with function .Hide()
    Code:
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    
    <script>
        $(document).ready(function() {
            if($('a').length >= 2) {
                window.alert('2 or more');
            }
        });
    </script>
    
    <a>element 1</a><br>
    <a>element 2</a><br>
    <a>element 3</a><br>
    <a>element 4</a><br>
    <a>element 5</a><br>
    <a>element 6</a>

  2. #2
    Junior Member
    Join Date
    Apr 2012
    Posts
    34
    Use :gt(index) selector:
    Code:
    $('a:gt(2)').hide();
    Or the faster slice function:
    Code:
    $('a').slice(2).hide();

  3. #3
    The Slice function is much faster.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts