jqueryjquery-selectorshideonchangeshow

How to select next element?


I'm working on tags list. There are maximum of five input tags. First two are shown by default... done! When user types something in some tag, it makes next tag visible. Not done.

This is what I have:

$('.group_interests:gt(1)').hide();

$('.group_interests:eq(1)').change( function() {

    $(this) // How to show next element like :eq(+1) or something.

});

I don't know how to select this:eq(+1). Then I would simply .show() and all would work!

Outcome:

$('.group_interests:gt(1)').hide();

$('.group_interests:visible').last().change( function() {

    $(this).next().show();

});

Solution

  • Have a look at jQuery.next().

    $('.group_interests:eq(1)').change(function() {
        $(this).next().show();
    });