2

I have some jQuery code.

$('#keywords').find('input').each(function () {
  if ('-1' != $(this).val().indexOf(ui.item.label)) {
    alert($(this).val());
    $(this).closest('.row').next().children().children().children().val('');
  }
});

I wonder if I can make some shorthand for triple .children() in case I do not "know" class or id of this elem.

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Stevan Tosic
  • 6,561
  • 10
  • 55
  • 110

1 Answers1

1

Considering you want to find <i> tag in following structure.

<div class="row">
</div>
<div>
 <div>
  <span>
    <i>
       Hello Selector
    </i>
  </span>

 </div>
</div>

You can use following script

$(function(){

    var text = $(".row").next().find("div span i").text();
    console.log(text);
});

Working Fiddle

K D
  • 5,889
  • 1
  • 23
  • 35
  • 1
    You have an extra period before `next()` and `li` in the find selector should just be `i`, (or vice versa,but there's no `ul` :P). I couldn't edit due to six character limit, but please consider correcting these. – Quangdao Nguyen Jan 24 '17 at 14:12