Reduce JavaScript code. Double event, selector into one Any idea how to write this code better."the html is nested tabs"
Two selectors and two similar events, in a function would be better or a pattern to reduce lines. eg .jsbin

$(function() {
  var $items  = $('#vtab&gt;ul&gt;li'),
      $items2 = $('#vtab2&gt;ul&gt;li');

  $items.mouseover(function() {
    var index = $items.index($(this));
    $items.removeClass('selected');
    $(this).addClass('selected');
    $('#vtab&gt;div').hide().eq(index).show();
  }).eq(1).mouseover();

  $items2.mouseover(function() {
    var index = $items2.index($(this));
    $items2.removeClass('selected');
    $(this).addClass('selected');
    $('#vtab2&gt;div').hide().eq(index).show();
  }).eq(1).mouseover();

});
Give those #vtabs a class and it should be simple:

$(function() {
    $('.vtab &gt; ul &gt; li').mouseover(function() {
        var $this = $(this);

        $this.addClass('selected').siblings().removeClass('selected');
        $this.closest('.vtab').find('div').eq($this.index()).hide().siblings().show();
    }).each(function() {
        $(this).find('&gt; ul &gt; li').eq(1).mouseover();
    });
});


Although I'd try turning it into a plugin at this point.