Jquery find next element inside a complex div

Asked

Viewed 878 times

0

Friends, I need to find an element in a tree DOM a little complex and I’m not getting the result. As I leave the input id = "barcode" i add new lines below and need to trigger the click on the next reader button.

The code below is with comments that you can understand better.

I am using the following code when exiting the first input but it’s not working:

var div_leitor = $('div.leitor').nextAll('div.leitor').first();
var barcode_clique = $(div_leitor).find('.barcode_btn');
$(barcode_clique).click();

HTML and comments are in gist as well as js: https://gist.github.com/rvgarimrj/cc8a6cb55364f9859e64785e1e0254bb

Could someone give me a hand ? Thank you

  • What do you mean "go out" when you write "When exiting input id = "barcode""?

  • The focusout event and I have the above code that doesn’t work. I need to find the next button in the next div and trigger the click event.

  • Forehead: $('#barcode').on('focusout', function(){ $(this).closest('.nested-fields').next().find('.barcode_btn').click();});

  • I was looking better at that HTML and it seems to me to be wrong... the Divs <div class="nested-fields"> shouldn’t be siblings? or HTML is actually correct and not at the same DOM level?

  • There is some error in this code. It is not working.

  • You saw my HTML question here ^ ?

  • Sergio, I created a gist with full html and my js for you to understand better. See if you can help: https://gist.github.com/rvgarimrj/cc8a6cb55364f9859e64785e1e0254bb

  • Can you put the rendered HTML in gist? the one you put in will be processed right?

  • Gist updated. This.html output is the result of my already processed Rails application.I’ve pasted the two htmls that will output this.html output.

Show 4 more comments
No answers

Browser other questions tagged

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