You need to use .next() since select
is the immediate next sibling of your input
with id text
:
alert(elem.next().attr('id'));
Your code is not working because .after() is used to
Insert content, specified by the parameter, after each element in the set of matched elements.