daGrevis
daGrevis

Reputation: 21333

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();

});

Upvotes: 0

Views: 196

Answers (3)

samir chauhan
samir chauhan

Reputation: 1543

Use $(this).next().show(); This will work.

Upvotes: 0

Tomas Aschan
Tomas Aschan

Reputation: 60574

Have a look at jQuery.next().

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

Upvotes: 2

hungryMind
hungryMind

Reputation: 6999

use next() method to get next element in dom

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

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

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

});

Upvotes: 0

Related Questions