How to select one element from another

5
<select class="form-control dropup bs-select-hidden" name="sys_nivel_acesso_id">
</select>
<div class="btn-group bootstrap-select form-control dropup">
  <button class="btn dropdown-toggle btn-default" data-toggle="dropdown" type="button" title="-----">
</div>
Hello, I would like a help to select via jQuery the element button from the element select of name sys_nivel_acesso_id with the intention of giving focus.

I've tried:

  • $('select[name="sys_nivel_acesso_id"]').next('div button').focus()
  • $('select[name="sys_nivel_acesso_id"]').next('div').next('button').focus()

But it did not work.

    
asked by anonymous 23.11.2015 / 19:00

2 answers

2

If div is just after select then you can use .next() that gives you a single element, or directly after select . You can use .siblings() but it returns many elements and will worsen performance when used with .find() because it will invoke it for each element found ..

$('select[name="sys_nivel_acesso_id"]').next().find('button').focus();

jsFiddle: link

    
23.11.2015 / 19:26
2

It looks like this:

$('select[name="sys_nivel_acesso_id"]').siblings('div').find('button');

Html:

  <select class="form-control dropup bs-select-hidden" name="sys_nivel_acesso_id"></select>
  <div class="btn-group bootstrap-select form-control dropup">
    <button class="btn dropdown-toggle btn-default" data-toggle="dropdown" type="button" title="-----">Text</button>
  </div>
    
23.11.2015 / 19:22