Div disabling jquery find next element

Asked

Viewed 87 times

0

Friends, I have the following question:

The following code below locates the next element from the select clicked: https://jsfiddle.net/cmftasor/

Works perfectly.

The problem is that by including the formatting daughter Ivs between the fields, it can no longer locate the next element, showing them as undefined, see the code:

https://jsfiddle.net/667qorya/

What was the mistake I made?

  • Is this what you’re looking for? https://jsfiddle.net/667qorya/1/

2 answers

0

From what I could tell from your code, the second example https://jsfiddle.net/667qorya/ the <select> is not inside the <div class=".caixa-dependentes2"> so when you try to call the function :

$('.caixa-dependentes2').on('change', '.aa', function(){
var proximo = $(this).nextAll('.bb').eq(0).val();
alert(proximo);
});

It doesn’t work because the <div> is empty

  • Ola Luks, and then, in this case, how can I make it work by keeping the Divs?

  • Put him inside the Ivs.

  • Sorry my ignorance Luks, so I saw the select is inside a cash-dependent daughter div. that’s what’s causing the problem?

  • I tried to use Parent -> "var proximo = $(this). Parent(). nextAll('.bb'). eq(0). val();" but also did not work

0

Try using it as follows:

var proximo = $(this).parents('.caixa-dependentes2').find('.bb').eq(0).val();
  • Hello Eduardo, I tested it here, so it displays only the values of the first Indice.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.