$(document).ready(function() {

  $('#example-traversing-filter1 h3').click(function() {
    $(this).next().find('li').filter(':even').toggleClass('highlight');
  });

  $('#example-traversing-filter2 h3').click(function() {
    $(this).next().find('li').filter(':gt(0):even').toggleClass('highlight');
  });
  
  $('#example-traversing-filter3 h3').click(function() {
    $(this).next().find('li').filter(':even:gt(0)').toggleClass('highlight');
  });
  
  $('#example-traversing-functionfilter1 h3').click(function() {
    $(this).next().find('li').filter(function(index) {
      return $("strong", this).length == 1;
    }).toggleClass('highlight');
  });


  $('#example-traversing-functionfilter2 h3').click(function() {
    $(this).next().find('li').filter(function(index) {
      return index % 3 == 2;
    }).toggleClass('highlight');
  });
  $('#example-traversing-not1 h3').click(function() {
    $(this).next().find('li').not(':even').toggleClass('highlight');
  });
  $('#example-traversing-not2 h3').click(function() {
    $(this).next().find('li').not(':odd:first').toggleClass('highlight');
  });
  $('#example-traversing-not3 h3').click(function() {
    $(this).next().find('li').not(':first:odd').toggleClass('highlight');
  });
  
  $('#example-traversing-notelement h3').click(function() {
    $(this).next().find('li').not(document.getElementById('notli')).toggleClass('highlight');
  });

  $('#example-traversing-eq h3').click(function() {
    $(this).next().find('li').eq(2).toggleClass('highlight');
  });
  
  $('#example-traversing-slice-start h3').click(function() {
    $(this).next().find('li').slice(2).toggleClass('highlight');
  });
  $('#example-traversing-slice-start-end h3').click(function() {
    $(this).next().find('li').slice(1, 3).toggleClass('highlight');
  });
  $('#example-traversing-add h3').click(function() {
    $(this).next().find('li').add('#example-traversing-add p').toggleClass('highlight');
  });
  $('#example-traversing-addelements h3').click(function() {
    $(this).next().find('li').add(document.getElementById('addp')).toggleClass('highlight');
  });
  
  $('#example-traversing-find h3').click(function() {
    $(this).next().find('li.item-ii').find('li').toggleClass('highlight');
  });
  
  $('#example-traversing-children h3').click(function() {
    $(this).next().find('ul.level-2').children().toggleClass('highlight');
  });
  $('#example-traversing-parents h3').click(function() {
    $(this).next().find('li.item-a').parents('ul').toggleClass('highlight');
  });
  $('#example-traversing-parent h3').click(function() {
    $(this).next().find('li.item-a').parent('ul').toggleClass('highlight');
  });
  $('#example-traversing-siblings h3').click(function() {
    $(this).next().find('.third-item').siblings().toggleClass('highlight');
  });

  $('#example-traversing-prev h3').click(function() {
    $(this).next().find('.third-item').prev().toggleClass('highlight');
  });
  $('#example-traversing-prev-all h3').click(function() {
    $(this).next().find('.third-item').prevAll().toggleClass('highlight');
  });

  $('#example-traversing-next h3').click(function() {
    $(this).next().find('.third-item').next().toggleClass('highlight');
  });
  
  $('#example-traversing-next-all h3').click(function() {
    $(this).next().find('.third-item').nextAll().toggleClass('highlight');
  });

  $('#example-traversing-has-class h3').click(function() {
    $(this).next().find('li').each(function() {
      if ( $(this).hasClass('third-item') ) {
        $(this).toggleClass('highlight');
      }
    });
  });
  
  $('#example-traversing-is h3').click(function() {
    $(this).next().find('li').each(function() {
      if ($(this).is(':nth-child(2)') ) {
        $(this).toggleClass('highlight');
      }
    });
  });
  $('#example-traversing-end h3').click(function() {
    $(this).next().find('ul.first')
    .find('.item-1')
      .toggleClass('highlight')
    .end()
    .find('.item-3')
      .toggleClass('highlight');
    });
  });


